dejson(S;O)

Converts a JSON string into 1010data values. (Available as of version 11.07)

Syntax

dejson(S;O)

Input

Argument Type Description
S text A JSON string of name-value pairs
O text A list of one or more special options: 'funnykeys', 'nofunnykeys', 'uqkeys', 'nouqkeys', and 'symbols'
  • 'funnykeys' tells dejson to convert funny keys. Funny keys are strings that contain anything other than alphanumeric characters and underscores, or do not begin with a letter. Funny keys are allowed by default.
  • 'nofunnykeys' tells dejson not to convert strings that contains anything other than alphanumeric characters and underscores, or do not begin with a letter.
  • 'nouqkeys' tells dejson not to covert unquoted keys in JSON strings, such as {a:2}. This is the default.
  • 'symbols' tells dejson that any strings in the resulting package should be interned as symbols, rather than cstrings/charvecs (Available as of version 15.02)
  • 'uqkeys' allows dejson to convert unquoted keys in JSON strings, such as {a:2}. Unquoted keys are not allowed by default.

Return Value

Returns a 1010data value represented by the JSON string. If the function cannot convert the JSON string, dejson throws an error message.

Example

The following example shows how dejson(string;) converts a "mixed" JSON string into package of name-value pairs that 1010data can use.

<base table="default.test.json"/>
<colord cols="mixed"/>
<willbe name="p" value="dejson(mixed;'symbols')"/>
<willbe name="a" value="pkg_default(p;'a';98.6)"/>
<willbe name="c" value="pkg_default(p;'c';'noun')"/>

The resulting table is as follows:

In column p, dejson(string;) converts the mixed JSON into a package of name-value pairs. Column a contains the value of a, and column c contains the value of c. In the third row of the table, the data type for c does not match the default, so the default value, noun, is used. The last row of the table does not contain an a or c value, so the a and c columns contain the default values 98.6 and noun, respectively. See pkg_default(P;K;D) for more information.