24 lines
1.1 KiB
Plaintext
24 lines
1.1 KiB
Plaintext
var json = {}
|
|
|
|
json.encode = function encode(val,replacer,space = 1,whitelist)
|
|
{
|
|
return JSON.stringify(val, replacer, space)
|
|
}
|
|
|
|
json.encode[cell.DOC] = `Produce a JSON text from a Javascript object. If a record value, at any level, contains a json() method, it will be called, and the value it returns (usually a simpler record) will be JSONified.
|
|
|
|
If the record does not have a json() method, and if whitelist is a record, then only the keys that are associated with true in the whitelist are included.
|
|
|
|
If the space input is true, then line breaks and extra whitespace will be included in the text.`
|
|
|
|
json.decode = function decode(text,reviver)
|
|
{
|
|
return JSON.parse(text,reviver)
|
|
}
|
|
|
|
json.decode[cell.DOC] = `The text text is parsed, and the resulting value (usually a record or an array) is returned.
|
|
|
|
The optional reviver input is a method that will be called for every key and value at every level of the result. Each value will be replaced by the result of the reviver function. This can be used to reform data-only records into method-bearing records, or to transform date strings into seconds.`
|
|
|
|
return json
|