Library json

To use this library in your code:

import encoding.json

Functions

decode bytes/ByteArray -> any
Decodes the bytes, which is a ByteArray in JSON format.
The result is null, or an instance of int, bool, float, string, List, or Map. The list elements and map values will also be one of these types.

decode-stream reader/any -> any
reader can be either an io.Reader, Reader or a BufferedReader.
Supportfor Reader and BufferedReader will be removed in the future.

encode obj/any [converter] -> ByteArray
Variant of encode obj.
If the obj is or contains a non-supported type, then the converter block is called with the object and an instance of the Encoder class. The converter is not called for map keys, which must still be strings.
The converter block is passed an object to be serialized and an instance of the Encoder class. If it returns a non-null value, that value will be serialized instead of the object that was passed in. Alternatively, the converter block can call the Encoder.encode, Encoder.put-list, or Encoder.put-unquoted methods on the encoder.

encode obj/any converter/Lambda -> ByteArray
Takes a Lambda instead of a block as converter.

encode obj/any -> ByteArray
Encodes the obj as a JSON ByteArray.
The obj must be a supported type, which means null, or an instance of int, bool, float, string, List or Map.
Maps must have only string keys. The elements of lists and the values of maps can be any of the above supported types.
UTF-8 encoding is used for strings.

encode-stream --writer/Writer obj/any [converter] -> none
If the obj is or contains a non-supported type, then the converter block is called with the object and an instance of the Encoder class. The converter is not called for map keys, which must still be strings.
The converter block is passed an object to be serialized and an instance of the Encoder class. If it returns a non-null value, that value will be serialized instead of the object that was passed in. Alternatively, the converter block can call the Encoder.encode, Encoder.put-list, or Encoder.put-unquoted methods on the encoder.

encode-stream --writer/Writer obj/any converter/Lambda -> none
Takes a Lambda instead of a block as converter.

encode-stream --writer/Writer obj/any -> none
Encodes the obj onto an io.Writer in JSON format.
The obj must be a supported type, which means null, or an instance of int, bool, float, string, List or Map.
Maps must have only string keys. The elements of lists and the values of maps can be any of the above supported types.
UTF-8 encoding is used on the writer.

parse str/string -> any
Decodes the str, which is a string in JSON format.
The result is null, or an instance of of int, bool, float, string, List, or Map. The list elements and map values will also be one of these types.

stringify obj/any [converter] -> string
Variant of stringify obj.
If the obj is or contains a non-supported type, then the converter block is called with the object and an instance of the Encoder class. The converter is not called for map keys, which must still be strings.
The converter block is passed an object to be serialized and an instance of the Encoder class. If it returns a non-null value, that value will be serialized instead of the object that was passed in. Alternatively, the converter block can call the Encoder.encode, Encoder.put-list, or Encoder.put-unquoted methods on the encoder.

stringify obj/any converter/Lambda -> string
Takes a Lambda instead of a block as converter.

stringify obj/any -> string
Encodes the obj as a JSON string.
The obj must be a supported type, which means null, or an instance of int, bool, float, string, List or Map.
Maps must have only string keys. The elements of lists and the values of maps can be any of the above supported types.