json

Import with:

import json

json.parse(text)

Parses a JSON string into ordinary Novum values.

let value = json.parse("{\"name\": \"Novum\", \"count\": 3}")

print(value["name"])
print(value["count"])

JSON values map to Novum as follows:

JSONNovum
nullNull
booleanBool
integerInt when representable
non-integer numberFloat
stringStr
arrayList
objectDict

JSON integers outside Novum’s Int range are rejected rather than silently truncated.

json.stringify(value)

Serializes a compatible Novum value to a compact JSON string:

let data = {
    "name": "Novum",
    "items": [1, 2, 3]
}

let text = json.stringify(data)
print(text)

The following Novum values can be serialized directly: Null, Unit (as JSON null), Bool, Int, Float, Str, List, and Dict.

Values such as classes, functions, iterators, matrices, and paths are not automatically JSON-serializable.

Non-finite floating-point values that cannot be represented as JSON numbers are rejected.