Functions -
lang.value
| clone |
Returns a clone of |
| cloneReadOnly |
Returns a clone of |
| fromJsonString |
Parses a string in JSON format and returns the the value that it represents. |
| isReadOnly |
Tests whether |
| mergeJson |
Merges two json values. |
| toJsonString |
Returns the string that represents |
| toString |
Performs a minimal conversion of a value to a string. |
Returns a clone of v.
A clone is a deep copy that does not copy immutable subtrees.
A clone can therefore safely be used concurrently with the original.
It corresponds to the Clone(v) abstract operation,
defined in the Ballerina Language Specification.
Parameters
- v null
-
source value
-
Return Type
(null) clone of
v
Returns a clone of v that is read-only, i.e. immutable.
It corresponds to the ImmutableClone(v) abstract operation,
defined in the Ballerina Language Specification.
Parameters
- v null
-
source value
-
Return Type
(null) immutable clone of
v
Parses a string in JSON format and returns the the value that it represents. All numbers in the JSON will be represented as float values. Returns an error if the string cannot be parsed.
Parameters
- str string
-
string representation of json
-
Return Type
(json | error) strparsed to json or error
Tests whether v is read-only, i.e. immutable
Returns true if read-only, false otherwise.
Parameters
- v anydata
-
source value
-
Return Type
(boolean) true if read-only, false otherwise
Merges two json values.
Parameters
- j1 json
-
json value
- j2 json
-
json value
-
Return Type
(json | error) the merge of
j1withj2or an error if the merge failsThe merge of
j1withj2is defined as follows:- if
j1is(), then the result isj2 - if
j2is(), then the result isj1 - if
j1is a mapping andj2is a mapping, then for each entry [k, j] in j2, setj1[k]to the merge ofj1[k]withj- if
j1[k]is undefined, then setj1[k]toj - if any merge fails, then the merge of
j1withj2fails - otherwise, the result is
j1.
- if
- otherwise, the merge fails
If the merge fails, then
j1is unchanged.
- if
Returns the string that represents v in JSON format.
Parameters
- v json
-
json value
-
Return Type
(string) string representation of json
Performs a minimal conversion of a value to a string. The conversion is minimal in particular in the sense that the conversion applied to a value that is already a string does nothing.
Parameters
- v any | error
-
the value to be converted to a string
-
Return Type
(string) a string resulting from the conversion
The result of
toString(v)is as follows:- if
vis a string, then returnsv - if
vis(), then returns an empty string - if
vis boolean, then the stringtrueorfalse - if
vis an int, then returnvrepresented as a decimal string - if
vis a float or decimal, then returnvrepresented as a decimal string, with a decimal point only if necessary, but without any suffix indicating the type ofv; returnNaN,Infinityfor positive infinity, and-Infinityfor negative infinity - if
vis a list, then returns the results toString on each member of the list separated by a space character - if
vis a map, then returns key=value for each member separated by a space character - if
vis xml, then returnsvin XML format (as if it occurred within an XML element) - if
vis table, TBD - if
vis an error, then a string consisting of the following in order- the string
error - a space character
- the reason string
- if the detail record is non-empty
- a space character
- the result of calling toString on the detail record
- the string
- if
vis an object, then- if
vprovides atoStringmethod with a string return type and no required methods, then the result of calling that method onv - otherwise,
objectfollowed by some implementation-dependent string
- if
- if
vis any other behavioral type, then the identifier for the behavioral type (function,future,service,typedescorhandle) followed by some implementation-dependent string
Note that
toStringmay produce the same string for two Ballerina values that are not equal (in the sense of the==operator).- if