aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorNathaniel McCallum <npmccallum@redhat.com>2017-04-18 11:05:38 -0400
committerNathaniel McCallum <npmccallum@redhat.com>2017-04-19 07:19:29 -0400
commit28666cead0a4c946b234d42f25b8a9db81f9bbdf (patch)
tree76461c6f2846a8d4acab5948be306de3650f7e17 /doc
parent74028ff958ce9ded8cf58bdee3151d3df94bafc4 (diff)
downloadjansson-28666cead0a4c946b234d42f25b8a9db81f9bbdf.zip
jansson-28666cead0a4c946b234d42f25b8a9db81f9bbdf.tar.gz
jansson-28666cead0a4c946b234d42f25b8a9db81f9bbdf.tar.bz2
Enable optional object/array members in json_pack()
Diffstat (limited to 'doc')
-rw-r--r--doc/apiref.rst23
1 files changed, 22 insertions, 1 deletions
diff --git a/doc/apiref.rst b/doc/apiref.rst
index bec4088..703261e 100644
--- a/doc/apiref.rst
+++ b/doc/apiref.rst
@@ -1269,6 +1269,14 @@ arguments.
.. versionadded:: 2.8
+``s*`` (string) [const char \*]
+ Like ``s``, but if the argument is *NULL*, do not output any value.
+ This format can only be used inside an object or an array. If used
+ inside an object, the corresponding key is additionally suppressed
+ when the value is omitted. See below for an example.
+
+ .. versionadded:: 2.11
+
``s#`` (string) [const char \*, int]
Convert a UTF-8 buffer of a given length to a JSON string.
@@ -1324,11 +1332,20 @@ arguments.
yourself.
``o?``, ``O?`` (any value) [json_t \*]
- Like ``o`` and ``O?``, respectively, but if the argument is
+ Like ``o`` and ``O``, respectively, but if the argument is
*NULL*, output a JSON null value.
.. versionadded:: 2.8
+``o*``, ``O*`` (any value) [json_t \*]
+ Like ``o`` and ``O``, respectively, but if the argument is
+ *NULL*, do not output any value. This format can only be used
+ inside an object or an array. If used inside an object, the
+ corresponding key is additionally suppressed. See below for an
+ example.
+
+ .. versionadded:: 2.11
+
``[fmt]`` (array)
Build an array with contents from the inner format string. ``fmt``
may contain objects and arrays, i.e. recursive value building is
@@ -1387,6 +1404,10 @@ More examples::
/* Concatenate strings together to build the JSON string "foobarbaz" */
json_pack("s++", "foo", "bar", "baz");
+ /* Create an empty object or array when optional members are missing */
+ json_pack("{s:s*,s:o*,s:O*}", "foo", NULL, "bar", NULL, "baz", NULL);
+ json_pack("[s*,o*,O*]", NULL, NULL, NULL);
+
.. _apiref-unpack: