JAVASCRIPT
JSON Utilities
All samples are using Ink.requireModules
, please read how to use it at Ink.requireModules section
Use this class to convert JSON strings to JavaScript objects
.parse()
and also to do the opposite operation .stringify()
.
Internally, the standard JSON implementation is used if available
Otherwise, the functions mimic the standard implementation.
Here's how to produce JSON from an existing object:
Ink.requireModules(['Ink.Util.Json_1'], function (Json) {
var obj = {
key1: 'value1',
key2: 'value2',
keyArray: ['arrayValue1', 'arrayValue2', 'arrayValue3']
};
Json.stringify(obj); // The above object as a JSON string
});
And here is how to parse JSON:
Ink.requireModules(['Ink.Util.Json_1'], function (Json) {
var source = '{"key": "value", "array": [true, null, false]}';
Json.parse(source); // The above JSON string as an object
});
Function name | Description |
---|---|
.parse(text, reviver) | Parses a JSON text through a function |
.stringify(input, convertToUnicode) | Serializes a JSON object into a string. |
Parses a JSON text through a function
text
{String} Input stringreviver
{Function} Function receiving `(key, value)`, and `this`=(containing object), used to walk objects.Code
Using second argument
Code
Serializes a JSON object into a string.
input
Data to be serialized into JSONconvertToUnicode
When `true`, converts string contents to unicode \uXXXXCode