It should be possible to configure encode and decode options in Commanded to be passed to the configured JSON serializer.
Jason supports the following encode and decode options.
Encode
:escape - controls how strings are encoded. Possible values are:
:json (default) - the regular JSON escaping as defined by RFC 7159.
:javascript_safe - additionally escapes the LINE SEPARATOR (U+2028)
and PARAGRAPH SEPARATOR (U+2029) characters to make the produced JSON
valid JavaSciprt.
:html_safe - similar to :javascript, but also escapes the /
caracter to prevent XSS.
:unicode_safe - escapes all non-ascii characters.
:maps - controls how maps are encoded. Possible values are:
:strict - checks the encoded map for duplicate keys and raises
if they appear. For example %{:foo => 1, "foo" => 2} would be
rejected, since both keys would be encoded to the string "foo".
:naive (default) - does not perform the check.
:pretty - controls pretty printing of the output. Possible values are:
true to pretty print with default configuration
a keyword of options as specified by Jason.Formatter.pretty_print/2.
Decode
:keys - controls how keys in objects are decoded. Possible values are:
:strings (default) - decodes keys as binary strings
:atoms - keys are converted to atoms using String.to_atom/1
*- :atoms! - keys are converted to atoms using String.to_existing_atom/1
:strings - controls how strings (including keys) are decoded. Possible values are:
*:reference (default) - when possible tries to create a sub-binary into the original
:copy - always copies the strings. This option is especially useful when parts of the decoded data will be stored for a long time (in ets or some process) to avoid keeping the reference to the original data.
It should be possible to configure encode and decode options in Commanded to be passed to the configured JSON serializer.
Jason supports the following encode and decode options.
Encode
:escape
- controls how strings are encoded. Possible values are::json
(default) - the regular JSON escaping as defined by RFC 7159.:javascript_safe
- additionally escapes the LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029) characters to make the produced JSON valid JavaSciprt.:html_safe
- similar to:javascript
, but also escapes the/
caracter to prevent XSS.:unicode_safe
- escapes all non-ascii characters.:maps
- controls how maps are encoded. Possible values are::strict
- checks the encoded map for duplicate keys and raises if they appear. For example%{:foo => 1, "foo" => 2}
would be rejected, since both keys would be encoded to the string"foo"
.:naive
(default) - does not perform the check.:pretty
- controls pretty printing of the output. Possible values are:true
to pretty print with default configurationJason.Formatter.pretty_print/2
.Decode
:keys
- controls how keys in objects are decoded. Possible values are::strings
(default) - decodes keys as binary strings:atoms
- keys are converted to atoms usingString.to_atom/1
*-:atoms!
- keys are converted to atoms usingString.to_existing_atom/1
:strings
- controls how strings (including keys) are decoded. Possible values are: *:reference
(default) - when possible tries to create a sub-binary into the original:copy
- always copies the strings. This option is especially useful when parts of the decoded data will be stored for a long time (in ets or some process) to avoid keeping the reference to the original data.