json v1.0.3 JSON.Parser.Charlist View Source
Implements a JSON Parser for Charlist values
Link to this section Summary
Functions
parses a valid JSON value, returns its elixir representation
parses valid JSON whitespace if it exists, returns the rest of the buffer
Link to this section Functions
parses a valid JSON value, returns its elixir representation
Examples
iex> JSON.Parser.Charlist.parse ''
{:error, :unexpected_end_of_buffer}
iex> JSON.Parser.Charlist.parse 'face0ff'
{:error, {:unexpected_token, 'face0ff'}}
iex> JSON.Parser.Charlist.parse '-hello'
{:error, {:unexpected_token, '-hello'}}
iex> JSON.Parser.Charlist.parse '129245'
{:ok, 129245, ''}
iex> JSON.Parser.Charlist.parse '7.something'
{:ok, 7, '.something'}
iex> JSON.Parser.Charlist.parse '-88.22suffix'
{:ok, -88.22, 'suffix'}
iex> JSON.Parser.Charlist.parse '-12e4and then some'
{:ok, -1.2e+5, 'and then some'}
iex> JSON.Parser.Charlist.parse '7842490016E-12-and more'
{:ok, 7.842490016e-3, '-and more'}
iex> JSON.Parser.Charlist.parse 'null'
{:ok, nil, ''}
iex> JSON.Parser.Charlist.parse 'false'
{:ok, false, ''}
iex> JSON.Parser.Charlist.parse 'true'
{:ok, true, ''}
iex> JSON.Parser.Charlist.parse '\"7.something\"'
{:ok, "7.something", ''}
iex> JSON.Parser.Charlist.parse '\"-88.22suffix\" foo bar'
{:ok, "-88.22suffix", ' foo bar'}
iex> JSON.Parser.Charlist.parse '[]'
{:ok, [], ''}
iex> JSON.Parser.Charlist.parse '["foo", 1, 2, 1.5] lala'
{:ok, ["foo", 1, 2, 1.5], ' lala'}
iex> JSON.Parser.Charlist.parse '{"result": "this will be a elixir result"} lalal'
{:ok, Enum.into([{"result", "this will be a elixir result"}], Map.new), ' lalal'}
parses valid JSON whitespace if it exists, returns the rest of the buffer
Examples
iex> JSON.Parser.Charlist.trim ''
''
iex> JSON.Parser.Charlist.trim 'xkcd'
'xkcd'
iex> JSON.Parser.Charlist.trim ' \t\r lalala '
'lalala '
iex> JSON.Parser.Charlist.trim ' \n\t\n fooo \u00dflalalal '
'fooo \u00dflalalal '