json v1.0.3 JSON.Parser.Bitstring View Source

Implements a JSON Parser for Bitstring 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.Bitstring.parse ""
{:error, :unexpected_end_of_buffer}

iex> JSON.Parser.Bitstring.parse "face0ff"
{:error, {:unexpected_token, "face0ff"}}

iex> JSON.Parser.Bitstring.parse "-hello"
{:error, {:unexpected_token, "-hello"}}

iex> JSON.Parser.Bitstring.parse "129245"
{:ok, 129245, ""}

iex> JSON.Parser.Bitstring.parse "7.something"
{:ok, 7, ".something"}

iex> JSON.Parser.Bitstring.parse "-88.22suffix"
{:ok, -88.22, "suffix"}

iex> JSON.Parser.Bitstring.parse "-12e4and then some"
{:ok, -1.2e+5, "and then some"}

iex> JSON.Parser.Bitstring.parse "7842490016E-12-and more"
{:ok, 7.842490016e-3, "-and more"}

iex> JSON.Parser.Bitstring.parse "null"
{:ok, nil, ""}

iex> JSON.Parser.Bitstring.parse "false"
{:ok, false, ""}

iex> JSON.Parser.Bitstring.parse "true"
{:ok, true, ""}

iex> JSON.Parser.Bitstring.parse "\"7.something\""
{:ok, "7.something", ""}

iex> JSON.Parser.Bitstring.parse "\"-88.22suffix\" foo bar"
{:ok, "-88.22suffix", " foo bar"}

iex> JSON.Parser.Bitstring.parse "\"star -> \\u272d <- star\""
{:ok, "star -> ✭ <- star", ""}

iex> JSON.Parser.Bitstring.parse "[]"
{:ok, [], ""}

iex> JSON.Parser.Bitstring.parse "[\"foo\", 1, 2, 1.5] lala"
{:ok, ["foo", 1, 2, 1.5], " lala"}

iex> JSON.Parser.Bitstring.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.Bitstring.trim ""
""

iex> JSON.Parser.Bitstring.trim "xkcd"
"xkcd"

iex> JSON.Parser.Bitstring.trim "  \t\r lalala "
"lalala "

iex> JSON.Parser.Bitstring.trim " \n\t\n fooo \u00dflalalal "
"fooo \u00dflalalal "