2017-12-23 19:10:12 -08:00
|
|
|
# jsx (v2.9.0) #
|
2011-11-29 20:28:19 -08:00
|
|
|
|
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
an erlang application for consuming, producing and manipulating [json][json].
|
|
|
|
inspired by [yajl][yajl]
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2015-10-08 22:50:04 -07:00
|
|
|
**jsx** is built via [rebar3][rebar3], [rebar][rebar] or [mix][mix] and continuous integration testing provided courtesy [travis-ci][travis]
|
2013-03-29 19:25:19 -07:00
|
|
|
|
2015-07-07 14:03:47 -07:00
|
|
|
current status: [](http://travis-ci.org/talentdeficit/jsx)
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
**jsx** is released under the terms of the [MIT][MIT] license
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2016-12-08 10:10:51 -08:00
|
|
|
copyright 2010-2016 alisdair sullivan
|
2012-09-03 21:44:47 -07:00
|
|
|
|
2014-01-14 00:39:06 +00:00
|
|
|
## really important note ##
|
|
|
|
|
2014-04-19 00:35:56 +00:00
|
|
|
there are a few changes for users upgrading from 1.x. see [CHANGES.md](CHANGES.md)
|
2014-06-16 23:45:25 +00:00
|
|
|
for the overview or [migrating from 1.x](#migrating) for the details
|
2014-01-14 00:39:06 +00:00
|
|
|
|
2014-04-22 13:24:47 -07:00
|
|
|
|
2012-03-20 19:37:02 -07:00
|
|
|
## index ##
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2012-03-20 19:42:03 -07:00
|
|
|
* [quickstart](#quickstart)
|
2012-05-23 21:57:01 -07:00
|
|
|
* [description](#description)
|
2014-04-19 00:35:56 +00:00
|
|
|
- [migrating from 1.x](#migrating)
|
2012-05-22 21:41:07 -07:00
|
|
|
- [json <-> erlang mapping](#json---erlang-mapping)
|
|
|
|
- [incomplete input](#incomplete-input)
|
2012-05-23 21:57:01 -07:00
|
|
|
* [data types](#data-types)
|
2012-05-27 12:45:14 -07:00
|
|
|
- [`json_term()`](#json_term)
|
|
|
|
- [`json_text()`](#json_text)
|
|
|
|
- [`event()`](#event)
|
|
|
|
- [`option()`](#option)
|
2012-05-23 21:57:01 -07:00
|
|
|
* [exports](#exports)
|
2012-05-27 20:26:33 -07:00
|
|
|
- [`encoder/3`, `decoder/3` & `parser/3`](#encoder3-decoder3--parser3)
|
|
|
|
- [`decode/1,2`](#decode12)
|
|
|
|
- [`encode/1,2`](#encode12)
|
|
|
|
- [`format/1,2`](#format12)
|
|
|
|
- [`minify/1`](#minify1)
|
|
|
|
- [`prettify/1`](#prettify1)
|
|
|
|
- [`is_json/1,2`](#is_json12)
|
|
|
|
- [`is_term/1,2`](#is_term12)
|
2014-10-28 04:43:32 +00:00
|
|
|
- [`maps_support/0`](#maps_support0)
|
2012-05-23 21:57:01 -07:00
|
|
|
* [callback exports](#callback_exports)
|
2012-05-27 20:31:56 -07:00
|
|
|
- [`Module:init/1`](#moduleinit1)
|
|
|
|
- [`Module:handle_event/2`](#modulehandle_event2)
|
2012-05-22 21:41:07 -07:00
|
|
|
* [acknowledgements](#acknowledgements)
|
|
|
|
|
|
|
|
|
|
|
|
## quickstart ##
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2016-06-15 15:49:15 -04:00
|
|
|
#### to add to a rebar3 project ####
|
|
|
|
Add to `rebar.config`
|
|
|
|
```erlang
|
2016-06-15 15:49:46 -04:00
|
|
|
...
|
2016-06-15 15:49:15 -04:00
|
|
|
{erl_opts, [debug_info]}.
|
|
|
|
{deps, [
|
2016-06-15 15:49:46 -04:00
|
|
|
...
|
2016-06-15 15:49:15 -04:00
|
|
|
{jsx, {git, "https://github.com/talentdeficit/jsx.git", {branch, "v2.8.0"}}}
|
|
|
|
]}.
|
2016-06-15 15:49:46 -04:00
|
|
|
...
|
2016-06-15 15:49:15 -04:00
|
|
|
```
|
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### to build the library and run tests ####
|
|
|
|
|
|
|
|
```bash
|
2015-10-08 22:50:04 -07:00
|
|
|
$ rebar3 compile
|
|
|
|
$ rebar3 eunit
|
2012-06-17 13:34:37 -07:00
|
|
|
$ rebar compile
|
|
|
|
$ rebar eunit
|
2015-10-08 22:50:04 -07:00
|
|
|
$ mix compile
|
|
|
|
$ mix eunit
|
2012-05-26 18:21:50 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
#### to convert a utf8 binary containing a json string into an erlang term ####
|
|
|
|
|
|
|
|
```erlang
|
|
|
|
1> jsx:decode(<<"{\"library\": \"jsx\", \"awesome\": true}">>).
|
|
|
|
[{<<"library">>,<<"jsx">>},{<<"awesome">>,true}]
|
2014-12-04 14:24:54 +00:00
|
|
|
2> jsx:decode(<<"{\"library\": \"jsx\", \"awesome\": true}">>, [return_maps]).
|
|
|
|
#{<<"awesome">> => true,<<"library">> => <<"jsx">>}
|
|
|
|
3> jsx:decode(<<"[\"a\",\"list\",\"of\",\"words\"]">>).
|
2012-05-26 18:21:50 -07:00
|
|
|
[<<"a">>, <<"list">>, <<"of">>, <<"words">>]
|
|
|
|
```
|
|
|
|
|
|
|
|
#### to convert an erlang term into a utf8 binary containing a json string ####
|
|
|
|
|
|
|
|
```erlang
|
|
|
|
1> jsx:encode([{<<"library">>,<<"jsx">>},{<<"awesome">>,true}]).
|
|
|
|
<<"{\"library\": \"jsx\", \"awesome\": true}">>
|
2014-04-19 00:35:56 +00:00
|
|
|
2> jsx:encode(#{<<"library">> => <<"jsx">>, <<"awesome">> => true}).
|
|
|
|
<<"{\"awesome\":true,\"library\":\"jsx\"}">>
|
|
|
|
3> jsx:encode([<<"a">>, <<"list">>, <<"of">>, <<"words">>]).
|
2012-05-26 18:21:50 -07:00
|
|
|
<<"[\"a\",\"list\",\"of\",\"words\"]">>
|
|
|
|
```
|
|
|
|
|
|
|
|
#### to check if a binary or a term is valid json ####
|
|
|
|
|
|
|
|
```erlang
|
|
|
|
1> jsx:is_json(<<"[\"this is json\"]">>).
|
|
|
|
true
|
|
|
|
2> jsx:is_json("[\"this is not\"]").
|
|
|
|
false
|
|
|
|
3> jsx:is_term([<<"this is a term">>]).
|
|
|
|
true
|
2013-06-04 01:14:55 +00:00
|
|
|
4> jsx:is_term([this, is, not]).
|
2012-05-26 18:21:50 -07:00
|
|
|
false
|
|
|
|
```
|
2011-11-29 20:29:49 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### to minify some json ####
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
1> jsx:minify(<<"{
|
|
|
|
\"a list\": [
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3
|
|
|
|
]
|
|
|
|
}">>).
|
|
|
|
<<"{\"a list\":[1,2,3]}">>
|
|
|
|
```
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### to prettify some json ####
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
1> jsx:prettify(<<"{\"a list\":[1,2,3]}">>).
|
|
|
|
<<"{
|
|
|
|
\"a list\": [
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3
|
|
|
|
]
|
|
|
|
}">>
|
|
|
|
```
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2015-10-08 22:58:19 -07:00
|
|
|
#### to compile **jsx** so that it always decodes json objects to maps ####
|
2015-10-08 22:50:04 -07:00
|
|
|
|
|
|
|
```bash
|
|
|
|
$ JSX_FORCE_MAPS rebar3 compile
|
|
|
|
$ JSX_FORCE_MAPS mix compile
|
|
|
|
```
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-23 21:57:01 -07:00
|
|
|
## description ##
|
2012-03-20 19:37:02 -07:00
|
|
|
|
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
**jsx** is an erlang application for consuming, producing and manipulating
|
2013-03-16 19:17:39 -07:00
|
|
|
[json][json]
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
**jsx** follows the json [spec][rfc4627] as closely as possible with allowances for
|
2013-10-29 01:43:46 +00:00
|
|
|
real world usage
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
**jsx** is pragmatic. the json spec allows extensions so **jsx** extends the spec in a
|
2013-10-29 01:43:46 +00:00
|
|
|
number of ways. see the section on `strict` in [options](#option) below though
|
2013-03-16 19:09:54 -07:00
|
|
|
|
2013-11-03 23:39:52 +00:00
|
|
|
json has no official comments but this parser allows c/c++ style comments.
|
2013-10-29 01:43:46 +00:00
|
|
|
anywhere whitespace is allowed you can insert comments (both `// ...` and `/* ... */`)
|
|
|
|
|
2014-08-19 17:47:44 -07:00
|
|
|
some particularly irresponsible json emitters leave trailing commas at the end of
|
|
|
|
objects or arrays. **jsx** allows a single trailing comma in input. multiple commas
|
|
|
|
in any posistion or a preceding comma are still errors
|
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
all **jsx** decoder input should be `utf8` encoded binaries. sometimes you get binaries
|
2013-10-29 01:43:46 +00:00
|
|
|
that are almost but not quite valid utf8 whether due to improper escaping or poor
|
2013-12-16 22:32:18 +00:00
|
|
|
encoding. **jsx** replaces invalid codepoints and poorly formed sequences with the
|
2014-06-16 23:45:25 +00:00
|
|
|
unicode replacement character (`u+FFFD`) but does it's best to return something
|
|
|
|
comprehensible
|
2013-10-29 01:43:46 +00:00
|
|
|
|
|
|
|
json only allows keys and strings to be delimited by double quotes (`u+0022`) but
|
2013-12-16 22:32:18 +00:00
|
|
|
javascript allows them to be delimited by single quotes (`u+0027`) as well. **jsx**
|
2013-10-29 01:43:46 +00:00
|
|
|
follows javascript in this. strings that start with single quotes can contain double
|
|
|
|
quotes but must end with single quotes and must escape any single quotes they contain
|
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
json and **jsx** only recognize escape sequences as outlined in the json spec. it just
|
2014-06-16 23:45:25 +00:00
|
|
|
ignores bad escape sequences leaving them in strings unaltered
|
2012-03-20 19:37:02 -07:00
|
|
|
|
|
|
|
|
2014-04-19 00:35:56 +00:00
|
|
|
### migrating from 1.x ###
|
|
|
|
|
2014-06-16 23:45:25 +00:00
|
|
|
if you're migrating from jsx v1.x to v2.x in most cases you won't need to
|
2014-04-19 00:35:56 +00:00
|
|
|
make any changes to your code
|
|
|
|
|
2015-10-08 22:58:19 -07:00
|
|
|
support for otp 17.0's new map type is now enabled by default when compiling
|
2014-04-19 00:35:56 +00:00
|
|
|
via rebar for any release that supports them. jsx should still compile cleanly for
|
2015-10-08 22:58:19 -07:00
|
|
|
earlier releases without any user intervention
|
2014-04-19 00:35:56 +00:00
|
|
|
|
|
|
|
if you used any of `replaced_bad_utf8`, `single_quoted_strings`, `comments`,
|
|
|
|
`ignored_bad_escapes` or `relax` you can simply omit them from your calls to jsx,
|
|
|
|
they are all enabled by default now. if you want stricter parsing see the new
|
|
|
|
[`strict` options](#option) available
|
|
|
|
|
|
|
|
if you were using jsx to parse partial json using it's streaming features it is now
|
|
|
|
disabled by default. you'll need to pass the `stream` option to calls to jsx functions
|
|
|
|
to reenable it
|
|
|
|
|
|
|
|
support for `pre_encode` and `post_decode` has been removed. they were fragile and hard
|
|
|
|
to understand and they prevented evolution of the encoding and decoding code
|
|
|
|
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
### json <-> erlang mapping ###
|
2012-03-20 19:37:02 -07:00
|
|
|
|
|
|
|
**json** | **erlang**
|
|
|
|
--------------------------------|--------------------------------
|
|
|
|
`number` | `integer()` and `float()`
|
2013-12-12 11:29:38 -08:00
|
|
|
`string` | `binary()` and `atom()`
|
2012-03-20 19:37:02 -07:00
|
|
|
`true`, `false` and `null` | `true`, `false` and `null`
|
|
|
|
`array` | `[]` and `[JSON]`
|
2014-04-19 00:35:56 +00:00
|
|
|
`object` | `#{}`, `[{}]` and `[{binary() OR atom() OR integer(), JSON}]`
|
2014-08-13 23:32:19 -07:00
|
|
|
see below | `datetime()`
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-25 09:30:54 -07:00
|
|
|
* numbers
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-11-03 23:39:52 +00:00
|
|
|
javascript and thus json represent all numeric values with floats. there's no
|
|
|
|
reason for erlang -- a language that supports arbitrarily large integers -- to
|
|
|
|
restrict all numbers to the ieee754 range
|
|
|
|
|
|
|
|
whenever possible, **jsx** will interpret json numbers that look like integers as
|
|
|
|
integers. other numbers will be converted to erlang's floating point type, which
|
|
|
|
is nearly but not quite iee754. negative zero is not representable in erlang (zero
|
|
|
|
is unsigned in erlang and `0` is equivalent to `-0`) and will be interpreted as
|
|
|
|
regular zero. numbers not representable are beyond the concern of this implementation,
|
|
|
|
and will result in parsing errors
|
|
|
|
|
|
|
|
when converting from erlang to json, floats are represented with their
|
2013-03-16 19:17:39 -07:00
|
|
|
shortest representation that will round trip without loss of precision. this
|
|
|
|
means that some floats may be superficially dissimilar (although
|
|
|
|
functionally equivalent). for example, `1.0000000000000001` will be
|
|
|
|
represented by `1.0`
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-25 09:30:54 -07:00
|
|
|
* strings
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-12-17 02:03:21 +00:00
|
|
|
json strings must be unicode encoded binaries or erlang atoms. in practice,
|
|
|
|
because **jsx** only accepts `utf8` binaries all binary strings must be `utf8`.
|
|
|
|
in addition to being unicode json strings restrict a number of codepoints and
|
|
|
|
define a number of escape sequences
|
2013-03-16 19:17:39 -07:00
|
|
|
|
|
|
|
json string escapes of the form `\uXXXX` will be converted to their
|
|
|
|
equivalent codepoints during parsing. this means control characters and
|
|
|
|
other codepoints disallowed by the json spec may be encountered in resulting
|
2013-11-03 23:39:52 +00:00
|
|
|
strings. the utf8 restriction means the surrogates are explicitly disallowed.
|
|
|
|
if a string contains escaped surrogates (`u+d800` to `u+dfff`) they are
|
|
|
|
interpreted but only when they form valid surrogate pairs. surrogates
|
|
|
|
encountered otherwise are replaced with the replacement codepoint (`u+fffd`)
|
2013-03-16 19:17:39 -07:00
|
|
|
|
|
|
|
all erlang strings are represented by **valid** `utf8` encoded binaries. the
|
2014-12-01 09:20:17 +00:00
|
|
|
encoder will check strings for conformance. badly formed `utf8` sequences may
|
|
|
|
be replaced with the replacement codepoint (`u+fffd`) according to the unicode
|
|
|
|
spec
|
2013-03-16 19:17:39 -07:00
|
|
|
|
|
|
|
this implementation performs no normalization on strings beyond that
|
|
|
|
detailed here. be careful when comparing strings as equivalent strings
|
|
|
|
may have different `utf8` encodings
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-25 09:30:54 -07:00
|
|
|
* true, false and null
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
the json primitives `true`, `false` and `null` are represented by the
|
|
|
|
erlang atoms `true`, `false` and `null`. surprise
|
2012-03-21 04:34:33 -07:00
|
|
|
|
2012-05-25 09:30:54 -07:00
|
|
|
* arrays
|
2012-03-21 04:34:33 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
json arrays are represented with erlang lists of json values as described
|
|
|
|
in this section
|
2012-03-21 04:34:33 -07:00
|
|
|
|
2012-05-25 09:30:54 -07:00
|
|
|
* objects
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2014-04-19 00:35:56 +00:00
|
|
|
json objects are represented by erlang proplists. json maps may also be
|
2014-12-01 09:20:17 +00:00
|
|
|
encoded to json and optionally decoded to maps (via the `return_maps`
|
|
|
|
option)
|
2014-04-19 00:35:56 +00:00
|
|
|
|
|
|
|
the empty object has the special representation `[{}]` to differentiate it
|
|
|
|
from the empty list. ambiguities like `[true, false]` prevent the use of
|
|
|
|
the shorthand form of property lists using atoms as properties so all
|
|
|
|
properties must be tuples. all keys must be encoded as in `string` or as
|
|
|
|
atoms or integers (which will be escaped and converted to binaries for
|
2014-06-15 22:12:07 +00:00
|
|
|
presentation to handlers). values should be valid json values. repeated
|
|
|
|
keys are tolerated in json text decoded to erlang terms but are not allowed
|
|
|
|
in erlang terms encoded to json
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2014-08-13 23:32:19 -07:00
|
|
|
* datetime
|
|
|
|
|
|
|
|
erlang datetime tuples (`{{Year, Month, Day}, {Hour, Min, Sec}}`) as returned
|
|
|
|
from `erlang:localtime/0` are automatically encoded as [iso8601][iso8601]
|
2015-03-03 10:43:04 -08:00
|
|
|
strings and are assumed to be UTC time. no conversion is attempted of json [iso8601][iso8601] strings in decoded json
|
2014-08-13 23:32:19 -07:00
|
|
|
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
### incomplete input ###
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
**jsx** can handle incomplete json texts. if the option `stream` is passed to the decoder
|
2013-10-29 01:43:46 +00:00
|
|
|
or parser and if a partial json text is parsed, rather than returning a term from
|
2013-12-16 22:32:18 +00:00
|
|
|
your callback handler, **jsx** returns `{incomplete, F}` where `F` is a function with
|
2013-10-29 01:43:46 +00:00
|
|
|
an identical API to the anonymous fun returned from `decoder/3`, `encoder/3` or
|
|
|
|
`parser/3`. it retains the internal state of the parser at the point where input
|
|
|
|
was exhausted. this allows you to parse as you stream json over a socket or file
|
|
|
|
descriptor, or to parse large json texts without needing to keep them entirely in
|
|
|
|
memory
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
however, it is important to recognize that **jsx** is conservative by default. **jsx** will
|
2013-10-29 01:43:46 +00:00
|
|
|
not consider the parsing complete even when input is exhausted and the json text is
|
|
|
|
unambiguously incomplete. to end parsing call the `incomplete` function with the
|
2014-08-13 23:00:35 -07:00
|
|
|
argument `end_stream` (or `end_json`) like:
|
2013-10-29 01:43:46 +00:00
|
|
|
|
|
|
|
```erlang
|
|
|
|
1> {incomplete, F} = jsx:decode(<<"[">>, [stream]).
|
|
|
|
{incomplete,#Fun<jsx_decoder.1.122947756>}
|
2014-08-13 23:00:35 -07:00
|
|
|
2> F(end_stream). % can also be `F(end_json)`
|
2013-10-29 01:43:46 +00:00
|
|
|
** exception error: bad argument
|
|
|
|
3> {incomplete, G} = F(<<"]">>).
|
|
|
|
{incomplete,#Fun<jsx_decoder.1.122947756>}
|
2014-08-13 23:00:35 -07:00
|
|
|
4> G(end_stream). % can also be `G(end_json)`
|
2013-10-29 01:43:46 +00:00
|
|
|
[]
|
|
|
|
```
|
2012-03-20 19:37:02 -07:00
|
|
|
|
|
|
|
|
2012-05-23 21:57:01 -07:00
|
|
|
## data types ##
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `json_term()` ####
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
json_term() = [json_term()]
|
2014-04-19 00:35:56 +00:00
|
|
|
| [{binary() | atom() | integer(), json_term()}]
|
|
|
|
| #{} % map of any size, not just the empty map
|
2012-05-26 18:21:50 -07:00
|
|
|
| true
|
|
|
|
| false
|
|
|
|
| null
|
|
|
|
| integer()
|
|
|
|
| float()
|
|
|
|
| binary()
|
2013-12-12 11:29:38 -08:00
|
|
|
| atom()
|
2014-08-13 23:32:19 -07:00
|
|
|
| datetime()
|
2012-05-26 18:21:50 -07:00
|
|
|
```
|
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
the erlang representation of json. binaries should be `utf8` encoded, or close
|
|
|
|
at least
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `json_text()` ####
|
|
|
|
|
|
|
|
```erlang
|
|
|
|
json_text() = binary()
|
|
|
|
```
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
a utf8 encoded binary containing a json string
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-10-29 01:43:46 +00:00
|
|
|
#### `event()` ####
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
2013-10-29 01:43:46 +00:00
|
|
|
event() = start_object
|
|
|
|
| end_object
|
|
|
|
| start_array
|
|
|
|
| end_array
|
|
|
|
| {key, binary()}
|
|
|
|
| {string, binary()}
|
|
|
|
| {integer, integer()}
|
|
|
|
| {float, float()}
|
|
|
|
| {literal, true}
|
|
|
|
| {literal, false}
|
|
|
|
| {literal, null}
|
|
|
|
| end_json
|
2012-05-26 18:21:50 -07:00
|
|
|
```
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-10-29 01:43:46 +00:00
|
|
|
the subset of [`token()`](#token) emitted by the decoder and encoder to handlers
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `option()` ####
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
2014-08-26 22:37:53 -07:00
|
|
|
option() = dirty_strings
|
|
|
|
| escaped_forward_slashes
|
2012-05-26 18:21:50 -07:00
|
|
|
| escaped_strings
|
2014-08-26 22:37:53 -07:00
|
|
|
| repeat_keys
|
|
|
|
| stream
|
2013-10-29 01:43:46 +00:00
|
|
|
| strict
|
|
|
|
| {strict, [strict_option()]}
|
2015-08-04 10:58:44 -07:00
|
|
|
| return_tail
|
2014-12-01 09:20:17 +00:00
|
|
|
| uescape
|
2014-08-26 22:37:53 -07:00
|
|
|
| unescaped_jsonp
|
2013-10-29 01:43:46 +00:00
|
|
|
|
|
|
|
strict_option() = comments
|
2014-08-19 17:47:44 -07:00
|
|
|
| trailing_commas
|
2013-10-29 01:43:46 +00:00
|
|
|
| utf8
|
|
|
|
| single_quotes
|
|
|
|
| escapes
|
|
|
|
```
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
**jsx** functions all take a common set of options. not all flags have meaning
|
2013-03-16 19:17:39 -07:00
|
|
|
in all contexts, but they are always valid options. functions may have
|
|
|
|
additional options beyond these. see
|
|
|
|
[individual function documentation](#exports) for details
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2014-08-26 22:37:53 -07:00
|
|
|
- `dirty_strings`
|
|
|
|
|
|
|
|
json escaping is lossy; it mutates the json string and repeated application
|
|
|
|
can result in unwanted behaviour. if your strings are already escaped (or
|
|
|
|
you'd like to force invalid strings into "json" you monster) use this flag
|
|
|
|
to bypass escaping. this can also be used to read in **really** invalid json
|
|
|
|
strings. everything between unescaped quotes are passed as is to the resulting
|
|
|
|
string term. note that this takes precedence over any other options
|
|
|
|
|
2012-05-27 12:41:53 -07:00
|
|
|
- `escaped_forward_slashes`
|
2012-03-29 00:24:31 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
json strings are escaped according to the json spec. this means forward
|
|
|
|
slashes (solidus) are only escaped when this flag is present. otherwise they
|
|
|
|
are left unescaped. you may want to use this if you are embedding json
|
|
|
|
directly into a html or xml document
|
2012-03-29 21:59:07 -07:00
|
|
|
|
2012-05-27 12:41:53 -07:00
|
|
|
- `escaped_strings`
|
2012-04-04 20:13:46 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
by default both the encoder and decoder return strings as utf8 binaries
|
|
|
|
appropriate for use in erlang. escape sequences that were present in decoded
|
|
|
|
terms are converted into the appropriate codepoint while encoded terms are
|
|
|
|
unaltered. this flag escapes strings as if for output in json, removing
|
|
|
|
control codes and problematic codepoints and replacing them with the
|
|
|
|
appropriate escapes
|
2012-03-29 21:59:07 -07:00
|
|
|
|
2014-08-26 22:37:53 -07:00
|
|
|
- `stream`
|
|
|
|
|
|
|
|
see [incomplete input](#incomplete-input)
|
2013-03-04 16:01:45 -08:00
|
|
|
|
2013-10-29 01:43:46 +00:00
|
|
|
- `strict`
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
as mentioned [earlier](#description), **jsx** is pragmatic. if you're more of a
|
2013-10-29 01:43:46 +00:00
|
|
|
json purist or you're really into bdsm stricter adherence to the spec is
|
|
|
|
possible. the following restrictions are available
|
|
|
|
|
|
|
|
* `comments`
|
|
|
|
|
|
|
|
comments are disabled and result in a `badarg` error
|
|
|
|
|
2014-08-19 17:47:44 -07:00
|
|
|
* `trailing_commas`
|
|
|
|
|
|
|
|
trailing commas in an object or list result in `badarg` errors
|
|
|
|
|
2013-10-29 01:43:46 +00:00
|
|
|
* `utf8`
|
|
|
|
|
|
|
|
invalid codepoints and malformed unicode result in `badarg` errors
|
|
|
|
|
|
|
|
* `single_quotes`
|
|
|
|
|
|
|
|
only keys and strings delimited by double quotes (`u+0022`) are allowed. the
|
|
|
|
single quote (`u+0027`) results in a `badarg` error
|
|
|
|
|
|
|
|
* `escapes`
|
|
|
|
|
|
|
|
escape sequences not adhering to the json spec result in a `badarg` error
|
|
|
|
|
2017-12-23 19:08:28 -08:00
|
|
|
* `control_codes`
|
|
|
|
|
|
|
|
control codes in strings result in `badarg` errors
|
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
any combination of these can be passed to **jsx** by using `{strict, [strict_option()]}`.
|
2017-12-23 19:08:28 -08:00
|
|
|
`strict` is equivalent to `{strict, [comments, trailing_commas, utf8, single_quotes, escapes, control_codes]}`
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2015-08-04 10:58:44 -07:00
|
|
|
- `return_tail`
|
|
|
|
|
|
|
|
upon reaching the end of a valid json term in an input stream return the term and any
|
|
|
|
remaining bytes in the input stream as `{with_tail, term(), binary()}` where the second
|
|
|
|
member of the tuple is the json term and the third is any remaining bytes. note that
|
|
|
|
leading whitespace will be stripped from the tail
|
|
|
|
|
2014-11-24 18:16:54 -08:00
|
|
|
- `uescape`
|
|
|
|
|
2014-12-03 23:02:02 -08:00
|
|
|
escape all codepoints outside the ascii range for 7 bit clean output. note
|
|
|
|
this escaping takes place even if no other string escaping is requested (via
|
|
|
|
`escaped_strings`)
|
2014-11-24 18:16:54 -08:00
|
|
|
|
2014-08-26 22:37:53 -07:00
|
|
|
- `unescaped_jsonp`
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2014-08-26 22:37:53 -07:00
|
|
|
javascript interpreters treat the codepoints `u+2028` and `u+2029` as
|
|
|
|
significant whitespace. json strings that contain either of these codepoints
|
|
|
|
will be parsed incorrectly by some javascript interpreters. by default,
|
|
|
|
these codepoints are escaped (to `\u2028` and `\u2029`, respectively) to
|
|
|
|
retain compatibility. this option simply removes that escaping
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-03-20 19:42:03 -07:00
|
|
|
|
2012-05-23 21:57:01 -07:00
|
|
|
## exports ##
|
2012-03-20 19:37:02 -07:00
|
|
|
|
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `encoder/3`, `decoder/3` & `parser/3` ####
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
decoder(Module, Args, Opts) -> Fun((JSONText) -> any())
|
|
|
|
encoder(Module, Args, Opts) -> Fun((JSONTerm) -> any())
|
|
|
|
parser(Module, Args, Opts) -> Fun((Tokens) -> any())
|
2012-05-25 11:55:26 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
Module = atom()
|
|
|
|
Args = any()
|
|
|
|
Opts = [option()]
|
|
|
|
JSONText = json_text()
|
|
|
|
JSONTerm = json_term()
|
2013-10-29 01:43:46 +00:00
|
|
|
Tokens = event() | [event()]
|
2012-05-26 18:21:50 -07:00
|
|
|
```
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
**jsx** is a json compiler with interleaved tokenizing, syntactic analysis and
|
2013-03-16 19:17:39 -07:00
|
|
|
semantic analysis stages. included are two tokenizers; one that handles json
|
|
|
|
texts (`decoder/3`) and one that handles erlang terms (`encoder/3`). there is
|
|
|
|
also an entry point to the syntactic analysis stage for use with user-defined
|
|
|
|
tokenizers (`parser/3`)
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
all three functions return an anonymous function that takes the appropriate type
|
|
|
|
of input and returns the result of performing semantic analysis, the tuple
|
|
|
|
`{incomplete, F}` where `F` is a new anonymous function (see
|
|
|
|
[incomplete input](#incomplete_input)) or a `badarg` error exception if
|
|
|
|
syntactic analysis fails
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
`Module` is the name of the callback module
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
`Args` is any term that will be passed to `Module:init/1` prior to syntactic
|
|
|
|
analysis to produce an initial state
|
2012-03-20 19:42:03 -07:00
|
|
|
|
2013-03-08 16:39:36 -05:00
|
|
|
`Opts` are detailed [here](#option)
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
check out [callback module documentation](#callback_exports) for details of
|
|
|
|
the callback module interface
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `decode/1,2` ####
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
decode(JSON) -> Term
|
|
|
|
decode(JSON, Opts) -> Term
|
2012-05-25 11:55:26 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
JSON = json_text()
|
|
|
|
Term = json_term()
|
2014-11-24 17:27:06 -08:00
|
|
|
Opts = [option() | labels | {labels, Label} | return_maps]
|
2013-07-05 03:11:01 +00:00
|
|
|
Label = binary | atom | existing_atom | attempt_atom
|
2012-05-26 18:21:50 -07:00
|
|
|
F = fun((any()) -> any())
|
|
|
|
```
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
`decode` parses a json text (a `utf8` encoded binary) and produces an erlang
|
|
|
|
term
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2013-07-03 21:51:26 -04:00
|
|
|
the option `labels` controls how keys are converted from json to
|
|
|
|
erlang terms. `binary` (the default behavior) does no conversion
|
|
|
|
beyond normal escaping. `atom` converts keys to erlang atoms and
|
2013-07-05 03:11:01 +00:00
|
|
|
results in a `badarg` error if the keys fall outside the range of erlang
|
2013-07-03 21:51:26 -04:00
|
|
|
atoms. `existing_atom` is identical to `atom` except it will not add
|
2013-07-05 03:11:01 +00:00
|
|
|
new atoms to the atom table and will result in a `badarg` error if the atom
|
|
|
|
does not exist. `attempt_atom` will convert keys to atoms when they exist,
|
|
|
|
and leave them as binary otherwise
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2014-11-24 17:27:06 -08:00
|
|
|
the option `return_maps` will attempt to return objects as maps instead of
|
|
|
|
proplists. this option has no effect when used with releases that do not
|
|
|
|
support maps
|
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
raises a `badarg` error exception if input is not valid json
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `encode/1,2` ####
|
2011-11-30 22:27:26 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
encode(Term) -> JSON
|
|
|
|
encode(Term, Opts) -> JSON
|
2012-05-25 11:55:26 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
Term = json_term()
|
|
|
|
JSON = json_text()
|
2013-10-29 01:43:46 +00:00
|
|
|
Opts = [option() | space | {space, N} | indent | {indent, N}]
|
2012-05-26 18:21:50 -07:00
|
|
|
N = pos_integer()
|
|
|
|
```
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2013-03-08 16:39:36 -05:00
|
|
|
`encode` converts an erlang term into json text (a `utf8` encoded binary)
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
the option `{space, N}` inserts `N` spaces after every comma and colon in your
|
|
|
|
json output. `space` is an alias for `{space, 1}`. the default is `{space, 0}`
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
the option `{indent, N}` inserts a newline and `N` spaces for each level of
|
|
|
|
indentation in your json output. note that this overrides spaces inserted after
|
|
|
|
a comma. `indent` is an alias for `{indent, 1}`. the default is `{indent, 0}`
|
2011-12-01 22:25:49 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
raises a `badarg` error exception if input is not a valid
|
|
|
|
[erlang representation of json](#json---erlang-mapping)
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2011-11-30 22:27:26 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `format/1,2` ####
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
format(JSON) -> JSON
|
|
|
|
format(JSON, Opts) -> JSON
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
JSON = json_text()
|
|
|
|
Opts = [option() | space | {space, N} | indent | {indent, N}]
|
|
|
|
N = pos_integer()
|
|
|
|
```
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
`format` parses a json text (a `utf8` encoded binary) and produces a new json
|
|
|
|
text according to the format rules specified by `Opts`
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
the option `{space, N}` inserts `N` spaces after every comma and colon in your
|
|
|
|
json output. `space` is an alias for `{space, 1}`. the default is `{space, 0}`
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
the option `{indent, N}` inserts a newline and `N` spaces for each level of
|
|
|
|
indentation in your json output. note that this overrides spaces inserted after
|
|
|
|
a comma. `indent` is an alias for `{indent, 1}`. the default is `{indent, 0}`
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
raises a `badarg` error exception if input is not valid json
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `minify/1` ####
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
minify(JSON) -> JSON
|
2012-03-20 19:37:02 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
JSON = json_text()
|
|
|
|
```
|
2011-11-30 20:06:16 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
`minify` parses a json text (a `utf8` encoded binary) and produces a new json
|
|
|
|
text stripped of whitespace
|
2011-12-14 21:07:50 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
raises a `badarg` error exception if input is not valid json
|
2011-12-14 21:07:50 -08:00
|
|
|
|
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `prettify/1` ####
|
2011-12-14 21:07:50 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
prettify(JSON) -> JSON
|
2011-11-30 22:27:26 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
JSON = json_text()
|
|
|
|
```
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
`prettify` parses a json text (a `utf8` encoded binary) and produces a new json
|
|
|
|
text equivalent to `format(JSON, [{space, 1}, {indent, 2}])`
|
2011-11-30 22:27:26 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
raises a `badarg` error exception if input is not valid json
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2011-12-14 21:07:50 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `is_json/1,2` ####
|
2011-11-30 20:06:16 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
is_json(MaybeJSON) -> true | false
|
|
|
|
is_json(MaybeJSON, Opts) -> true | false
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
MaybeJSON = any()
|
|
|
|
Opts = options()
|
|
|
|
```
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
returns true if input is a valid json text, false if not
|
2011-12-14 21:07:50 -08:00
|
|
|
|
2012-05-27 20:29:48 -07:00
|
|
|
what exactly constitutes valid json may be [altered](#option)
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2011-12-14 21:07:50 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `is_term/1,2` ####
|
2011-12-14 21:32:17 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
is_term(MaybeJSON) -> true | false
|
|
|
|
is_term(MaybeJSON, Opts) -> true | false
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
MaybeJSON = any()
|
|
|
|
Opts = options()
|
|
|
|
```
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
returns true if input is a valid erlang representation of json, false if not
|
|
|
|
|
2013-03-16 19:09:54 -07:00
|
|
|
what exactly constitutes valid json may be altered via [options](#option)
|
2011-12-14 21:32:17 -08:00
|
|
|
|
2014-10-28 04:43:32 +00:00
|
|
|
|
|
|
|
#### `maps_support/0` ####
|
|
|
|
|
|
|
|
```erlang
|
|
|
|
maps_support() -> true | false
|
|
|
|
```
|
|
|
|
|
|
|
|
if **jsx** was compiled with map support enabled returns `true`, else
|
|
|
|
`false`
|
|
|
|
|
|
|
|
|
2012-05-23 21:57:01 -07:00
|
|
|
## callback exports ##
|
2011-12-14 21:32:17 -08:00
|
|
|
|
2013-12-16 22:32:18 +00:00
|
|
|
the following functions should be exported from a **jsx** callback module
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `Module:init/1` ####
|
|
|
|
|
|
|
|
```erlang
|
|
|
|
Module:init(Args) -> InitialState
|
|
|
|
|
|
|
|
Args = any()
|
|
|
|
InitialState = any()
|
|
|
|
```
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
whenever any of `encoder/3`, `decoder/3` or `parser/3` are called, this function
|
|
|
|
is called with the `Args` argument provided in the calling function to obtain
|
|
|
|
`InitialState`
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
#### `Module:handle_event/2` ####
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
```erlang
|
|
|
|
Module:handle_event(Event, State) -> NewState
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
Event = [event()]
|
|
|
|
State = any()
|
|
|
|
NewState = any()
|
|
|
|
```
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
semantic analysis is performed by repeatedly calling `handle_event/2` with a
|
|
|
|
stream of events emitted by the tokenizer and the current state. the new state
|
|
|
|
returned is used as the input to the next call to `handle_event/2`. the
|
|
|
|
following events must be handled:
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `start_object`
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
the start of a json object
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `end_object`
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
the end of a json object
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `start_array`
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
the start of a json array
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `end_array`
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
the end of a json array
|
2012-05-23 22:25:07 -07:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `{string, binary()}`
|
2011-11-30 20:06:16 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
a json string. it will usually be a `utf8` encoded binary. see the
|
2013-10-29 01:43:46 +00:00
|
|
|
[options](#option) for possible exceptions. note that keys are also
|
|
|
|
json strings
|
2011-12-14 21:07:50 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `{integer, integer()}`
|
2011-12-14 21:07:50 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
an erlang integer (bignum)
|
2011-12-14 21:32:17 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `{float, float()}`
|
2011-12-14 21:32:17 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
an erlang float
|
2011-12-14 21:32:17 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `{literal, true}`
|
2011-12-14 21:32:17 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
the atom `true`
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `{literal, false}`
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
the atom `false`
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `{literal, null}`
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
the atom `null`
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2012-05-26 18:21:50 -07:00
|
|
|
- `end_json`
|
2012-03-04 18:40:00 -08:00
|
|
|
|
2013-03-16 19:17:39 -07:00
|
|
|
this event is emitted when syntactic analysis is completed. you should
|
|
|
|
do any cleanup and return the result of your semantic analysis
|
2011-12-14 21:32:17 -08:00
|
|
|
|
|
|
|
|
2012-05-22 21:41:07 -07:00
|
|
|
## acknowledgements ##
|
2011-11-30 20:06:16 -08:00
|
|
|
|
2015-08-08 17:46:51 -07:00
|
|
|
jsx wouldn't be what it is without the contributions of [Paul J. Davis](https://github.com/davisp), [Lloyd Hilaiel](https://github.com/lloyd), [John Engelhart](https://github.com/johnezang), [Bob Ippolito](https://github.com/etrepum), [Brujo Benavides](https://github.com/elbrujohalcon), [Alex Kropivny](https://github.com/amtal), [Steve Strong](https://github.com/srstrong), [Michael Truog](https://github.com/okeuday), [Devin Torres](https://github.com/devinus), [fogfish](https://github.com/fogfish), [emptytea](https://github.com/emptytea), [John Daily](https://github.com/macintux), [Ola Bäckström](https://github.com/olabackstrom), [Joseph Crowe](https://github.com/JosephCrowe), [Patrick Gombert](https://github.com/patrickgombert), [Eshengazin S. Kuat](https://github.com/eskuat), [Max Lapshin](https://github.com/maxlapshin), [Bikram Chatterjee](https://github.com/c-bik), [Michael Uvarov](https://github.com/arcusfelis), [Led](https://github.com/Ledest) and [tvv](https://github.com/tvv)
|
2011-11-29 20:28:19 -08:00
|
|
|
|
2012-03-20 19:37:02 -07:00
|
|
|
[json]: http://json.org
|
2011-11-30 20:06:16 -08:00
|
|
|
[yajl]: http://lloyd.github.com/yajl
|
|
|
|
[MIT]: http://www.opensource.org/licenses/mit-license.html
|
2015-10-08 22:50:04 -07:00
|
|
|
[rebar3]: https://rebar3.org
|
2013-03-29 19:06:19 -07:00
|
|
|
[rebar]: https://github.com/rebar/rebar
|
2015-10-08 22:50:04 -07:00
|
|
|
[mix]: http://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html
|
2012-03-14 11:42:35 -07:00
|
|
|
[meck]: https://github.com/eproxus/meck
|
2013-03-29 19:20:32 -07:00
|
|
|
[rfc4627]: http://tools.ietf.org/html/rfc4627
|
2013-07-03 21:51:26 -04:00
|
|
|
[travis]: https://travis-ci.org/
|
2014-04-22 13:24:47 -07:00
|
|
|
[jsxn]: https://github.com/talentdeficit/jsxn
|
2014-08-13 23:32:19 -07:00
|
|
|
[iso8601]: http://www.iso.org/iso/iso8601
|