json
Module json provides JSON encoding and decoding.
Functions
marshal
Function signature
marshal(v object) stringReturns a JSON string representing the given value. Raises an error if the value cannot be marshalled.
Example
>>> m := {one: 1, two: 2}
>>> json.marshal(m)
"{\"one\":1,\"two\":2}"unmarshal
Function signature
unmarshal(s string) objectReturns the value represented by the given JSON string. Raises an error if the string cannot be unmarshalled.
Example
>>> json.unmarshal("{\"one\":1,\"two\":2}")
{"one": 1, "two": 2}
>>> json.unmarshal("{bad") // raises value errorvalid
Function signature
valid(s string) boolReturns whether the given string is valid JSON.
Example
>>> json.valid("42")
true
>>> json.valid("{oops")
false