iskra / jsonx

JSONX is an Erlang library for efficient decode and encode JSON, written in C.
Other
91 stars 32 forks source link

Ignore null member encoding #9

Closed kuenishi closed 11 years ago

kuenishi commented 11 years ago

Add option to encoder/2, which enables ignoring null or undefined atoms to make small output json.

  Encoder = jsonx:encoder([{r0, record_info(r0)}], [{ignore, [null]}]),
  <<"{}">> = Encoder({r0, null, null, null}).

Of course this encoding is irreversible, but sometimes size matters - the record can be rebuilt if json schema is known, or record name is included inside the object.

  [{<<"record_name">>, <<"r0">>}] = jsonx:decode(<<"{\"record_name\":\"r0\"}">>),
  {r0, null, null, null} = rebuild_r0([{<<"record_name">>, <<"r0">>}], null).
kuenishi commented 11 years ago

Thank you!