Module jsonpull

These functions both read and transform JSON data into Erlang types.

Description

These functions both read and transform JSON data into Erlang types.

The main reading functions return {ok, {Value, Rest}} or {error, Atom}.

They sit a level above the jsonpull_read module, so they also skip whitespace.

Function Index

null/1Try to read a null from the JSON.
boolean/1Try to read a boolean from the JSON.
string/1Try to read a string from the JSON.
iolist/1Try to read a string from the JSON as an iolist.
existing_atom/1Try to read a string from the JSON as an already existing atom.
number/1Try to read a number from the JSON.
integer/1Try to read an integer from the JSON.
float/1Try to read a float from the JSON.
array/1Try to read an array from the JSON.
element/1Try to read the next array element from the JSON.
object/1Try to read an object from the JSON.
key/1Try to read the next object key from the JSON.
unescape_and_strip/1Turn a raw JSON string into a properly translated Erlang iolist.
strip/1Strips the quotes from a raw JSON string.
skip_value/1Skips over the next value in the provided JSON binary.

Function Details

null/1

null(JSON::binary()) -> {ok, {Value::null, Rest::binary()}} | {error, not_null}

Try to read a null from the JSON. If it's there, it will be returned as the atom 'null'.

boolean/1

boolean(JSON::binary()) -> {ok, {Value::boolean(), Rest::binary()}} | {error, not_boolean}

Try to read a boolean from the JSON. If it's there, it will be returned as the atom 'true' or 'false'.

string/1

string(JSON::binary()) -> {ok, {Value::binary(), Rest::binary()}} | {error, not_string | unterminated_string | invalid_escape_sequence}

Try to read a string from the JSON. If it's there, it will be returned as a binary string with all escape sequences processed.

See also: iolist/1.

iolist/1

iolist(JSON::binary()) -> {ok, {Value::iolist(), Rest::binary()}} | {error, not_string | unterminated_string | invalid_escape_sequence}

Try to read a string from the JSON as an iolist. This is like reading a string, except escape sequences are handled differently.

This may be more efficient in some cases.

See also: string/1.

existing_atom/1

existing_atom(JSON::binary()) -> {ok, {Value::atom(), Rest::binary()}} | {error, not_string | unterminated_string | not_existing_atom}

Try to read a string from the JSON as an already existing atom. This function will not parse escape sequences.

See also: string/1.

number/1

number(JSON::binary()) -> {ok, {Value::binary(), Rest::binary()}} | {error, not_number}

Try to read a number from the JSON. If it's there, it will be returned as the original binary string version.

See also: float/1, integer/1.

integer/1

integer(JSON::binary()) -> {ok, {Value::integer(), Rest::binary()}} | {error, not_integer}

Try to read an integer from the JSON. This function will discriminate against floats and only return integers.

See also: float/1, number/1.

float/1

float(JSON::binary()) -> {ok, {Value::float(), Rest::binary()}} | {error, not_float}

Try to read a float from the JSON. This function will discriminate against integers and only return floats.

See also: integer/1, number/1.

array/1

array(JSON::binary()) -> {ok, {begin_array, Rest::binary()}} | {error, not_array}

Try to read an array from the JSON. If it's there, the atom 'begin_array' will be returned.

Structured types are handled differently in pull parsers. For more info, read the Overview.

element/1

element(JSON::binary()) -> {ok, {element, Rest::binary()}} | {ok, {end_array, Rest::binary()}}

Try to read the next array element from the JSON. If there is an element, it will be represented as the atom 'element'

If the array is ending, the atom 'end_array' will be returned.

Structured types are handled differently in pull parsers. For more info, read the Overview.

object/1

object(JSON::binary()) -> {ok, {begin_object, Rest::binary()}} | {error, not_object}

Try to read an object from the JSON. If there is an object, the atom 'begin_object' will be returned.

Structured types are handled differently in pull parsers. For more info, read the Overview.

key/1

key(JSON::binary()) -> {ok, {Key::binary(), Rest::binary()}} | {ok, {end_object, Rest::binary()}} | {error, missing_colon_after_key | unterminated_key | key_not_string | unterminated_string | invalid_escape_sequence}

Try to read the next object key from the JSON. If there is a key, it will be returned as a binary string.

If the object is ending, the atom 'end_object' will be returned.

Structured types are handled differently in pull parsers. For more info, read the Overview.

unescape_and_strip/1

unescape_and_strip(String::binary()) -> {ok, iolist()} | unterminated_string | invalid_escape_sequence

Turn a raw JSON string into a properly translated Erlang iolist.

Note: You may need to use unicode:characters_to_binary/list afterwards if you don't want an iolist.

Using iolist_to_binary will only work if there are no weird unicode escape sequences!

strip/1

strip(X1) -> any()

Strips the quotes from a raw JSON string.

See also: unescape_and_strip/1.

skip_value/1

skip_value(JSONIn::binary()) -> JSONOut::binary() | {error, atom()}

Skips over the next value in the provided JSON binary.


Generated by EDoc