| 1 |
<?xml version='1.0'?> <!--*-nxml-*--> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="sd-json" |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>sd-json</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
|
| 14 |
<refmeta> |
| 15 |
<refentrytitle>sd-json</refentrytitle> |
| 16 |
<manvolnum>3</manvolnum> |
| 17 |
</refmeta> |
| 18 |
|
| 19 |
<refnamediv> |
| 20 |
<refname>sd-json</refname> |
| 21 |
<refpurpose>APIs for Dealing with JSON Objects</refpurpose> |
| 22 |
</refnamediv> |
| 23 |
|
| 24 |
<refsynopsisdiv> |
| 25 |
<funcsynopsis> |
| 26 |
<funcsynopsisinfo>#include <systemd/sd-json.h></funcsynopsisinfo> |
| 27 |
</funcsynopsis> |
| 28 |
|
| 29 |
<cmdsynopsis> |
| 30 |
<command>pkg-config --cflags --libs libsystemd</command> |
| 31 |
</cmdsynopsis> |
| 32 |
</refsynopsisdiv> |
| 33 |
|
| 34 |
<refsect1> |
| 35 |
<title>Description</title> |
| 36 |
|
| 37 |
<para><filename>sd-json.h</filename> is part of |
| 38 |
<citerefentry><refentrytitle>libsystemd</refentrytitle><manvolnum>3</manvolnum></citerefentry> and |
| 39 |
provides APIs to parse, generate, format and otherwise operate with JSON objects.</para> |
| 40 |
|
| 41 |
<para>The API's central data structure is <type>JsonVariant</type> which encapsulates a JSON object, |
| 42 |
array, string, boolean, number or null value. These data structures are mostly considered immutable after |
| 43 |
construction (i.e. their contents will not change, but some meta-data might, such as reference counters).</para> |
| 44 |
|
| 45 |
<para>The APIs broadly fall into five categories:</para> |
| 46 |
|
| 47 |
<itemizedlist> |
| 48 |
<listitem><para>APIs to directly operate with <type>JsonVariant</type> objects, in the |
| 49 |
<function>sd_json_variant*</function> namespace.</para></listitem> |
| 50 |
|
| 51 |
<listitem><para>APIs to construct complex JSON objects, in the <function>sd_json_build*</function> |
| 52 |
namespace.</para></listitem> |
| 53 |
|
| 54 |
<listitem><para>APIs to map <type>JsonVariant</type> objects and their fields to matching fields in C |
| 55 |
structures, in the <function>sd_json_dispatch*</function> namespace.</para></listitem> |
| 56 |
|
| 57 |
<listitem><para>APIs to convert a string representation of a JSON object into a |
| 58 |
<type>JsonVariant</type> object, in the <function>sd_json_parse*</function> |
| 59 |
namespace.</para></listitem> |
| 60 |
|
| 61 |
<listitem><para>APIs to convert an <type>JsonVariant</type> object into its string representation, in |
| 62 |
the <function>sd_json_format*</function> namespace.</para></listitem> |
| 63 |
</itemizedlist> |
| 64 |
|
| 65 |
<para>This JSON library will internally encode JSON integer numbers in the range |
| 66 |
<constant>INT64_MIN</constant>…<constant>UINT64_MAX</constant> into native 64bit signed or unsigned |
| 67 |
integers, and will reproduce them without loss of precision. Non-integer numbers are stored in 64bit IEEE |
| 68 |
floating point numbers.</para> |
| 69 |
|
| 70 |
<para>If the functions return string arrays, these are generally |
| 71 |
<constant>NULL</constant> terminated and need to be freed by the |
| 72 |
caller with the libc |
| 73 |
<citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 74 |
call after use, including the strings referenced therein. |
| 75 |
Similarly, individual strings returned need to be freed, as |
| 76 |
well.</para> |
| 77 |
|
| 78 |
<para>As a special exception, instead of an empty string array <constant>NULL</constant> may be returned, |
| 79 |
which should be treated equivalent to an empty string array.</para> |
| 80 |
</refsect1> |
| 81 |
|
| 82 |
<xi:include href="libsystemd-pkgconfig.xml" /> |
| 83 |
|
| 84 |
<refsect1> |
| 85 |
<title>See Also</title> |
| 86 |
<para><simplelist type="inline"> |
| 87 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 88 |
<member><citerefentry><refentrytitle>sd-varlink</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 89 |
<member><citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 90 |
</simplelist></para> |
| 91 |
</refsect1> |
| 92 |
</refentry> |