View Source jsonpull_read (jsonpull v0.1.1)

These are the most basic functions you can use to read data from JSON. They take the value you ask for out of binary JSON if it's there. They return {Bin, Rest} or an atom representing an error. They will also skip whitespace.

For more information on how to use these functions and what a pull parser is, read the Overview.

Summary

Functions

Try to read an array from the JSON. If an array is starting here, the binary <<"[">> will be returned.

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

Try to read the next array element from the JSON. If there is an element, either the binary <<",">> or an empty binary will be returned.

Try to read the next object key from the JSON. If there is a key, it will be returned as a raw string, with the same caveats as string/1.

Try to read a null from the JSON. If it's there, it will be returned as a binary <<"null">>.
Try to read a number from the JSON. If it's there, it will be returned as a binary string in its original form.

Try to read an object from the JSON. If there is an object, the binary <<"{">> will be returned.

Try to read a string from the JSON. If it's there, it will be returned without any sort of processing. This means escape sequences and the quotation marks on the edges are still there.

See also: jsonpull:unescape_and_strip/1.

Functions

-spec array(JSON :: binary()) -> {ReadValue :: binary(), Rest :: binary()} | not_array.

Try to read an array from the JSON. If an array is starting here, the binary <<"[">> will be returned.

Structured types are handled differently in pull parsers. For more info, read the Overview.
-spec boolean(JSON :: binary()) -> {ReadValue :: binary(), Rest :: binary()} | not_boolean.
Try to read a boolean from the JSON. If it's there, it will be returned as a binary <<"true">> or <<"false">>.
-spec element(JSON :: binary()) -> {ReadValue :: binary(), Rest :: binary()}.

Try to read the next array element from the JSON. If there is an element, either the binary <<",">> or an empty binary will be returned.

If the array is ending, the binary <<"]">> will be returned.

Structured types are handled differently in pull parsers. For more info, read the Overview.
-spec key(JSON :: binary()) ->
       {ReadValue :: binary(), Rest :: binary()} |
       missing_colon_after_key | unterminated_key | key_not_string.

Try to read the next object key from the JSON. If there is a key, it will be returned as a raw string, with the same caveats as string/1.

If the object is ending, the binary <<"}">> will be returned.

Structured types are handled differently in pull parsers. For more info, read the Overview.
-spec null(JSON :: binary()) -> {ReadValue :: binary(), Rest :: binary()} | not_null.
Try to read a null from the JSON. If it's there, it will be returned as a binary <<"null">>.
-spec number(JSON :: binary()) -> {ReadValue :: binary(), Rest :: binary()} | not_number.
Try to read a number from the JSON. If it's there, it will be returned as a binary string in its original form.
-spec object(JSON :: binary()) -> {ReadValue :: binary(), Rest :: binary()} | not_object.

Try to read an object from the JSON. If there is an object, the binary <<"{">> will be returned.

Structured types are handled differently in pull parsers. For more info, read the Overview.
-spec string(JSON :: binary()) ->
          {ReadValue :: binary(), Rest :: binary()} | not_string | unterminated_string.
Try to read a string from the JSON. If it's there, it will be returned without any sort of processing. This means escape sequences and the quotation marks on the edges are still there.

See also: jsonpull:unescape_and_strip/1.