samson

Search:
Group by:

See also

Procs

proc toJson5[T](value: T): string
Serialize value to it's JSON5 representation. This representation will be valid JSON as well, with a single exception: the special float values NaN, +Infinity, and -Infinity are all supported.

Examples:

type
  Obj = object
    field1: int
    field2: string

let obj = Obj(field1: 1234, field2: "foobar")
doAssert toJson5(obj) == """{"field1": 1234, "field2": "foobar"}"""
## 'NaN' is not valid in JSON, but in JSON5 it is!
doAssert toJson5(NaN) == "NaN"
proc fromJson5(input: string; T: typedesc): T:type
Deserialize the JSON5 string input into a value of type T.

Examples:

type
  Obj = object
    field1: int
    field2: string

let input = """{"field1": 1234, "field2": "foobar"}"""
doAssert fromJson5(input, Obj) == Obj(field1: 1234, field2: "foobar")