glazer (glazer v0.5.14)
View SourceFast JSON/YAML/CSV encoding and decoding using the glaze C++ library.
The public API is split across glazer_json,
glazer_yaml, and glazer_csv.
By default nulls are represented as the atom null. To change it
application-wide, set the null env key in your config:
Erlang:
{glazer, [{null, nil}]}.Elixir:
config :glazer, null: nil
Summary
Functions
Decode a JSON number string to an integer.
Raises invalid_number_format on invalid input.
Encode an integer to its JSON string representation.
Raises badarg if Int is not an integer.
Find value(s) in Term by walking Path.
Format an error message with io_lib:format/2 and flatten to a binary.
Return build information about the loaded NIF library
Decode a JSON number string to an integer, returning {ok, Int} or
{error, invalid_number_format} instead of raising.
Types
Functions
Compile a jq-style path expression into a path()
for use with find/2.
Supports a small subset of jq syntax:
.- identity (returns the input term itself).foo,.foo.bar- field access (map key).["foo bar"]- bracketed field access, for keys with special characters.[]- iterate: every element of a list, or every value of a map.[N],.[-N]- index into a list (negative indices count from the end)
Segments can be chained freely, e.g. .a.b[].c[0].
Raises {invalid_path, Filter} if Filter doesn't match this grammar.
Example
1> glazer:compile_path(<<".a[].b">>).
[{field,<<"a">>},iterate,{field,<<"b">>}]
Decode a JSON number string to an integer.
Raises invalid_number_format on invalid input.
Encode an integer to its JSON string representation.
Raises badarg if Int is not an integer.
Find value(s) in Term by walking Path.
Term is typically a decoded JSON/YAML document: nested maps and lists.
Path is either a path() produced by compile_path/1, or a raw
jq-style filter string (compiled on the fly via compile_path/1 — raises
{invalid_path, Filter} if it doesn't parse).
As a string, Path supports a small subset of jq
syntax (see compile_path/1 for the full grammar), e.g. .a.b[].c[0].
Returns the list of values found at the end of Path. An empty list means
no match. .[] steps fan out over every element of a list (or every value
of a map), so a path containing .[] can produce multiple results.
Examples
1> Doc = #{<<"a">> => [#{<<"b">> => 1}, #{<<"b">> => 2}, #{<<"c">> => 3}]}.
2> glazer:find(Doc, <<".a[].b">>).
[1, 2]
3> glazer:find(Doc, <<".a[2].c">>).
[3]
4> glazer:find(Doc, <<".a[-1].c">>).
[3]
5> glazer:find(Doc, <<".">>).
[Doc]
6> glazer:find(#{<<"foo bar">> => 1}, <<".[\"foo bar\"]">>).
[1]
Format an error message with io_lib:format/2 and flatten to a binary.
-spec info() -> #{app_version => binary(), version => binary(), pgo => boolean(), optimization => none | 'O1' | 'O3'}.
Return build information about the loaded NIF library:
app_version: thevsnfromglazer.app.srcthat this build was madefrom (e.g. `<<"0.5.9">>`)version:git describeof the checkout the NIF was built from(e.g. `<<"0.5.9-3-abc123">>`, with a trailing `*` if the working tree was dirty at build time)pgo:trueif built with profile-guided optimisation(`make optimize` / `make PGO=use`)optimization:none,'O1'(debug/ASan builds), or'O3'(release)
Example
1> glazer:info().
#{app_version => <<"0.5.9">>, version => <<"0.5.9-3-abc123">>,
pgo => true, optimization => 'O3'}
Decode a JSON number string to an integer, returning {ok, Int} or
{error, invalid_number_format} instead of raising.