Browse Source

Introduce common_option/0 for shared options.

Heinz N. Gies 7 years ago
parent
commit
11220ada8e
2 changed files with 21 additions and 10 deletions
  1. 14 5
      doc/jsone.md
  2. 7 5
      src/jsone.erl

+ 14 - 5
doc/jsone.md

@@ -15,6 +15,18 @@ JSON decoding/encoding module.
 
 
 
+### <a name="type-common_option">common_option()</a> ###
+
+
+<pre><code>
+common_option() = undefined_as_null
+</code></pre>
+
+`undefined_as_null`: <br />
+- Treats `undefined` in Erlang as the conversion target for `null` in JSON. This means that `undefined` will be encoded to `null` and `null` will be decoded to `undefined`<br />
+
+
+
 ### <a name="type-datetime_encode_format">datetime_encode_format()</a> ###
 
 
@@ -60,7 +72,7 @@ datetime_format() = iso8601
 
 
 <pre><code>
-decode_option() = {object_format, tuple | proplist | map} | {allow_ctrl_chars, boolean()} | {keys, binary | atom | existing_atom | attempt_atom} | undefined_as_null
+decode_option() = {object_format, tuple | proplist | map} | {allow_ctrl_chars, boolean()} | {keys, binary | atom | existing_atom | attempt_atom} | <a href="#type-common_option">common_option()</a>
 </code></pre>
 
 `object_format`: <br />
@@ -92,7 +104,7 @@ binary string if fails find one.
 
 
 <pre><code>
-encode_option() = native_utf8 | canonical_form | {float_format, [<a href="#type-float_format_option">float_format_option()</a>]} | {datetime_format, <a href="#type-datetime_encode_format">datetime_encode_format()</a>} | {object_key_type, string | scalar | value} | {space, non_neg_integer()} | {indent, non_neg_integer()} | undefined_as_null
+encode_option() = native_utf8 | canonical_form | {float_format, [<a href="#type-float_format_option">float_format_option()</a>]} | {datetime_format, <a href="#type-datetime_encode_format">datetime_encode_format()</a>} | {object_key_type, string | scalar | value} | {space, non_neg_integer()} | {indent, non_neg_integer()} | <a href="#type-common_option">common_option()</a>
 </code></pre>
 
 `native_utf8`: <br />
@@ -125,9 +137,6 @@ encode_option() = native_utf8 | canonical_form | {float_format, [<a href="#type-
 - Inserts a newline and `N` spaces for each level of indentation <br />
 - default: `0` <br />
 
-`undefined_as_null`: <br />
-- Treats `undefined` in Erlang as the conversion target for `null` in JSON. This means that `undefined` will be encoded to `null` and `null` will be decoded to `undefined`<br />
-
 
 
 ### <a name="type-float_format_option">float_format_option()</a> ###

+ 7 - 5
src/jsone.erl

@@ -183,6 +183,11 @@
 -type timezone() :: utc | local | utc_offset_seconds().
 -type utc_offset_seconds() :: -86399..86399.
 
+-type common_option() :: undefined_as_null.
+%%
+%% `undefined_as_null': <br />
+%% - Treats `undefined' in Erlang as the conversion target for `null' in JSON. This means that `undefined' will be encoded to `null' and `null' will be decoded to `undefined'<br />
+
 -type encode_option() :: native_utf8
                        | canonical_form
                        | {float_format, [float_format_option()]}
@@ -190,7 +195,7 @@
                        | {object_key_type, string | scalar | value}
                        | {space, non_neg_integer()}
                        | {indent, non_neg_integer()}
-                       | undefined_as_null.
+                       | common_option().
 %% `native_utf8': <br />
 %% - Encodes UTF-8 characters as a human-readable(non-escaped) string <br />
 %%
@@ -220,14 +225,11 @@
 %% `{indent, N}': <br />
 %% - Inserts a newline and `N' spaces for each level of indentation <br />
 %% - default: `0' <br />
-%%
-%% `undefined_as_null': <br />
-%% - Treats `undefined' in Erlang as the conversion target for `null' in JSON. This means that `undefined' will be encoded to `null' and `null' will be decoded to `undefined'<br />
 
 -type decode_option() :: {object_format, tuple | proplist | map}
                        | {allow_ctrl_chars, boolean()}
                        | {'keys', 'binary' | 'atom' | 'existing_atom' | 'attempt_atom'}
-                       | undefined_as_null.
+                       | common_option().
 %% `object_format': <br />
 %% - Decoded JSON object format <br />
 %% - `tuple': An object is decoded as `{[]}' if it is empty, otherwise `{[{Key, Value}]}'. <br />