tmux_json (libtmux for Erlang v0.0.1)
View SourceDecode bounded JSON using OTP's json parser and binary object keys.
Documents are limited to 256 KiB before parsing and 32 nested containers
during parsing. Duplicate keys are rejected before overwriting values, even
when different escapes spell the same key. Trailing input is rejected. Numbers
stay in the shared exact integer range. Integral decimal tokens are converted
exactly; fractional tokens that round to integers are rejected. Field
validation decides whether a remaining float is permitted. Syntax and resource
errors have a root path; duplicate-key errors retain their complete document
path. Use tmux_filter:from_wire/2 to validate decoded filter data.
Summary
Functions
-spec decode(binary()) -> {ok, json:decode_value()} | {error, map()}.
Return a decoded value or a structured error without creating payload atoms.
1> tmux_json:decode(<<"{\"a\": [1, true, null]}">>).
{ok,#{<<"a">> => [1,true,null]}}
2> tmux_json:decode(<<"{\"a\": {\"x\": 1, \"x\": 2}}">>).
{error,#{code => duplicate_key,path => [<<"a">>,<<"x">>]}}
3> tmux_json:decode(<<"[] []">>).
{error,#{code => trailing_input,path => []}}