Json

JSON value type, tag constants, conversion helpers, parser-result types, and serialization helpers.


Tag constants


JSON

JSON stores one tagged value over Int64, Real64, Cond, String, JSON Array, and String JSON HashTable.

Methods

Conversion helpers

Object values store one String JSON HashTable, and array values store one JSON Array.


JSONParserResult


Parser model


parseStringToJSON (source -- result)

Parses one accepted UTF-8 source into JSONParserResult.


saveJSONToString (json -- string)

Serializes one JSON value to a formatted String.


Examples

Successful object parse

"Json" use
"control" use

{} () {} [
  result: "{\"x\":1}" parseStringToJSON;
  @result.@success TRUE same printStack _:;
  @result.@finished TRUE same printStack _:;
  @[email protected] JSONObject same printStack _:;
  @[email protected] 1 same printStack _:;
] "main" exportFunction

Expected Output During Compilation

TRUE
TRUE
TRUE
TRUE

Trailing input and duplicate key

"Json" use
"control" use

{} () {} [
  trailing: "{} x" parseStringToJSON;
  @trailing.@success TRUE same printStack _:;
  @trailing.@finished FALSE same printStack _:;
  @trailing.@errorInfo.@position.@offset 3 same printStack _:;

  duplicate: "{\"x\":1,\"x\":2}" parseStringToJSON;
  @duplicate.@success FALSE same printStack _:;
] "main" exportFunction

Expected Output During Compilation

TRUE
TRUE
TRUE
TRUE

Parse and serialize array

"Json" use
"String" use
"control" use

{} Int32 {} [
  result: "[1,true]" parseStringToJSON;
  result.success ~ [
    1
  ] [
    result.json saveJSONToString print
    0
  ] if
] "main" exportFunction

Expected Output

[
  1,
  true
]

See also