View Source Json5 (json5 v0.4.0)
Convert Json5 to Elixir term and back
Summary
Functions
parse json5 input as elixir type.
To keep the precision of the given numbers the integers and floats are cast to Decimal
options:
- object_key_function: (binary) -> any
- use given function to format the object key
- object_key_existing_atom: boolean
- format the object key with
String.to_existing_atom/1
- format the object key with
- object_key_atom: boolean
- format the object key with
String.to_atom/1
- if none of the above options are set return the key as a binary (String.t())
- format the object key with
- object_new_function: ({any, any}) -> any
- function to create a map from the list of parsed tuples, by default uses
Map.new/1
- function to create a map from the list of parsed tuples, by default uses
- backend: [
Json5.Decode.Backend.Combine
,Json5.Decode.Backend.Yecc
]- select the backend to be used (Defaults to Combine).
- The Combine backend is coded with the json5 spec (with unicode) in mind, but a lot slower (about 2000x slower than
Jason
) - The Yecc backend is a lot faster (about 6x slower than
Jason
) but not that rigorous based on the json5 spec. It is just written to make the existing tests work.
iex> Json5.decode("{array: [1, 2, 3], map: {'null': null, test: 1, }, }")
{:ok, %{
"map" => %{
"test" => Decimal.new(1),
"null" => nil
},
"array" => [
Decimal.new(1),
Decimal.new(2),
Decimal.new(3)
]
}}
Same as decode/2
but raises on error
Encode elixir input as json5. Contains some simple formatting options
options:
- pretty: boolean
- compact: boolean
iex> Json5.encode(%{map: %{test: 1, null: nil}, array: [1,2,3]})
{:ok, "{array: [1, 2, 3], map: {'null': null, test: 1, }, }"}
iex> Json5.encode(%{map: %{test: 1, null: nil}, array: [1,2,3]}, pretty: true)
{:ok, """
{
array: [
1,
2,
3,
],
map: {
'null': null,
test: 1,
},
}
"""}
iex> Json5.encode(%{map: %{test: 1, null: nil}, array: [1,2,3]}, compact: true)
{:ok, "{array:[1,2,3],map:{'null':null,test:1}}"}
Same as encode/2
but raises on error