Module jstream

A JSON stream library based on: The JavaScript Object Notation (JSON) Data Interchange Format (rfc7159).

Copyright © (C) 2020, Jan Henry Nystrom <JanHenryNystrom@gmail.com> -------------------------------------------------------------------

Authors: Jan Henry Nystrom (JanHenryNystrom@gmail.com).

Description

A JSON stream library based on: The JavaScript Object Notation (JSON) Data Interchange Format (rfc7159)

JSON is represented as follows:

value : true | false | null | object | array | number | string

object : map array : [value*] string : UTF-8 binary number : integer() | float() true : atom(true) false : atom(false) null : atom(null)

Strings can be represented by atoms when generating JSON, but will not not be generated when converting JSON to erlang. Strings are restricted to UTF-8

When converting Erlang terms to JSON iolists are generated but it can generate a binary if so instructed.

Objects as maps, multiple occurrences of the members is not supported.

Data Types

acc()

acc() = [{jstring(), json()}]

array()

array() = [json()]

complete()

complete() = boolean()

cont()

cont() = {decode, stack()} | {object, {complete(), expect()}, acc(), stack()} | {array, {first(), complete()}, array(), stack()} | {string, binary(), stack()} | {unescape, binary(), stack()} | {number, stage(), phase(), list(), stack()}

expect()

expect() = name | comma | colon

first()

first() = boolean()

json()

json() = true | false | null | number() | jstring() | object() | array()

jstring()

jstring() = binary()

name()

name() = jstring()

object()

object() = map()

phase()

phase() = int | float | exp

stack()

stack() = [{array, array()} | {name, acc()} | {value, {name(), acc()}}]

stage()

stage() = sign | zero | pre | post

Function Index

decode/1 Decodes the binary into a tuple of structured Erlang term and the remaining binary or a continuation if the binary did not contain a complete JSON value.
decode/2 Decodes a binary and a continuation into a tuple of structured Erlang term and the remaining binary or a continuation if the binary did not contain a complete JSON value.
encode/1 Encodes the structured Erlang term as an iolist.
encode/2 Encodes the structured Erlang term as an iolist or binary.

Function Details

decode/1

decode(B::binary()) -> {json(), binary()} | {more, cont()}

Decodes the binary into a tuple of structured Erlang term and the remaining binary or a continuation if the binary did not contain a complete JSON value. The continuation can be used by decode/2 with a binary containing the rest of the JSON value to decode.

decode/2

decode(B::binary(), X2::cont()) -> {json(), binary()} | {more, cont()}

Decodes a binary and a continuation into a tuple of structured Erlang term and the remaining binary or a continuation if the binary did not contain a complete JSON value. The continuation can be used with a binary containing the rest of the JSON value to decode.

encode/1

encode(Object::json()) -> iodata()

Encodes the structured Erlang term as an iolist. Equivalent of encode(Term, iolist) -> JSON.

encode/2

encode(V::json(), X2::binary) -> binary()

Encodes the structured Erlang term as an iolist or binary. Encode will give an exception if the erlang term is not well formed. Options are: binary -> a binary is returned iolist -> an iolist is returned (default)


Generated by EDoc