View Source jsonpull (jsonpull v0.1.1)
These functions both read and transform JSON data into Erlang types.
The main reading functions return {ok, {Value, Rest}}
or {error, Atom}
.
jsonpull_read
module, so they also skip whitespace.
Summary
Functions
Try to read an array from the JSON. If it's there, the atom 'begin_array'
will be returned.
'true'
or 'false'
.Try to read the next array element from the JSON. If there is an element, it will be represented as the atom 'element'
See also: string/1.
Try to read a string from the JSON as an iolist. This is like reading a string, except escape sequences are handled differently.
Try to read the next object key from the JSON. If there is a key, it will be returned as a binary string.
'null'
.Try to read an object from the JSON. If there is an object, the atom 'begin_object'
will be returned.
See also: iolist/1.
See also: unescape_and_strip/1.
Turn a raw JSON string into a properly translated Erlang iolist.
Functions
-spec 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.
-spec boolean(JSON :: binary()) -> {ok, {Value :: boolean(), Rest :: binary()}} | {error, not_boolean}.
'true'
or 'false'
.
-spec 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.
-spec existing_atom(JSON :: binary()) ->
{ok, {Value :: atom(), Rest :: binary()}} |
{error, not_string | unterminated_string | not_existing_atom}.
See also: string/1.
-spec float(JSON :: binary()) -> {ok, {Value :: float(), Rest :: binary()}} | {error, not_float}.
-spec integer(JSON :: binary()) -> {ok, {Value :: integer(), Rest :: binary()}} | {error, not_integer}.
-spec 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.
-spec 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.
-spec null(JSON :: binary()) -> {ok, {Value :: null, Rest :: binary()}} | {error, not_null}.
'null'
.
-spec number(JSON :: binary()) -> {ok, {Value :: binary(), Rest :: binary()}} | {error, not_number}.
-spec 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.
-spec skip_value(JSONIn :: binary()) -> JSONOut :: binary() | {error, atom()}.
-spec string(JSON :: binary()) ->
{ok, {Value :: binary(), Rest :: binary()}} |
{error, not_string | unterminated_string | invalid_escape_sequence}.
See also: iolist/1.
See also: unescape_and_strip/1.
-spec 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!