components/jansson/doc/man3lib/libjansson.3lib
author Tomas Heran <tomas.heran@oracle.com>
Fri, 17 Apr 2015 01:30:52 -0700
branchs11-update
changeset 4141 c6a303a2f8c5
permissions -rw-r--r--
PSARC/2014/362 Jansson 19903653 Jansson - C library for working with JSON should be added to Userland
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4141
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     1
.\" Man page generated from reStructuredText.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     2
.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     3
.TH "LIBJANSSON" "3LIB" "October 28, 2014" "2.7" "Jansson"
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     4
.SH NAME
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     5
jansson \- Jansson Documentation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     6
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     7
This is the documentation for \fI\%Jansson\fP 2.7, last updated October 28, 2014\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     8
.SH INTRODUCTION
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     9
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    10
\fI\%Jansson\fP is a C library for encoding, decoding and manipulating JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    11
data. Its main features and design principles are:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    12
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    13
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    14
Simple and intuitive API and data model
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    15
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    16
Comprehensive documentation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    17
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    18
No dependencies on other libraries
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    19
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    20
Full Unicode support (UTF\-8)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    21
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    22
Extensive test suite
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    23
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    24
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    25
Jansson is licensed under the \fI\%MIT license\fP; see LICENSE in the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    26
source distribution for details.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    27
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    28
Jansson is used in production and its API is stable. It works on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    29
numerous platforms, including numerous Unix like systems and Windows.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    30
It\(aqs suitable for use on any system, including desktop, server, and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    31
small embedded systems.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    32
.SH CONTENTS
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    33
.SS Getting Started
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    34
.SS Compiling and Installing Jansson
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    35
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    36
The Jansson source is available at
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    37
\fI\%http://www.digip.org/jansson/releases/\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    38
.SS Unix\-like systems (including MinGW)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    39
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    40
Unpack the source tarball and change to the source directory:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    41
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    42
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    43
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    44
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    45
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    46
bunzip2 \-c jansson\-2.7\&.tar.bz2 | tar xf \-
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    47
cd jansson\-2.7
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    48
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    49
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    50
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    51
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    52
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    53
The source uses GNU Autotools (\fI\%autoconf\fP, \fI\%automake\fP, \fI\%libtool\fP), so
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    54
compiling and installing is extremely simple:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    55
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    56
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    57
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    58
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    59
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    60
\&./configure
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    61
make
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    62
make check
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    63
make install
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    64
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    65
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    66
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    67
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    68
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    69
To change the destination directory (\fB/usr/local\fP by default), use
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    70
the \fB\-\-prefix=DIR\fP argument to \fB\&./configure\fP\&. See \fB\&./configure
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    71
\-\-help\fP for the list of all possible installation options. (There are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    72
no options to customize the resulting Jansson binary.)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    73
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    74
The command \fBmake check\fP runs the test suite distributed with
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    75
Jansson. This step is not strictly necessary, but it may find possible
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    76
problems that Jansson has on your platform. If any problems are found,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    77
please report them.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    78
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    79
If you obtained the source from a Git repository (or any other source
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    80
control system), there\(aqs no \fB\&./configure\fP script as it\(aqs not kept in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    81
version control. To create the script, the build system needs to be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    82
bootstrapped. There are many ways to do this, but the easiest one is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    83
to use \fBautoreconf\fP:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    84
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    85
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    86
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    87
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    88
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    89
autoreconf \-vi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    90
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    91
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    92
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    93
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    94
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    95
This command creates the \fB\&./configure\fP script, which can then be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    96
used as described above.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    97
.SS CMake (various platforms, including Windows)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    98
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    99
Jansson can be built using \fI\%CMake\fP\&. Create a build directory for an
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   100
out\-of\-tree build, change to that directory, and run \fBcmake\fP (or \fBccmake\fP,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   101
\fBcmake\-gui\fP, or similar) to configure the project.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   102
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   103
See the examples below for more detailed information.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   104
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   105
\fBNOTE:\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   106
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   107
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   108
In the below examples \fB\&..\fP is used as an argument for \fBcmake\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   109
This is simply the path to the jansson project root directory.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   110
In the example it is assumed you\(aqve created a sub\-directory \fBbuild\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   111
and are using that. You could use any path you want.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   112
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   113
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   114
.SS Unix (Make files)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   115
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   116
Generating make files on unix:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   117
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   118
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   119
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   120
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   121
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   122
bunzip2 \-c jansson\-2.7\&.tar.bz2 | tar xf \-
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   123
cd jansson\-2.7
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   124
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   125
mkdir build
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   126
cd build
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   127
cmake .. # or \fBccmake ..()\fP for a GUI.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   128
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   129
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   130
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   131
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   132
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   133
Then to build:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   134
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   135
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   136
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   137
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   138
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   139
make
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   140
make check
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   141
make install
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   142
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   143
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   144
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   145
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   146
.SS Windows (Visual Studio)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   147
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   148
Creating Visual Studio project files from the command line:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   149
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   150
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   151
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   152
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   153
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   154
<unpack>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   155
cd jansson\-2.7
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   156
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   157
md build
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   158
cd build
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   159
cmake \-G "Visual Studio 10" ..
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   160
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   161
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   162
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   163
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   164
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   165
You will now have a \fIVisual Studio Solution\fP in your build directory.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   166
To run the unit tests build the \fBRUN_TESTS\fP project.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   167
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   168
If you prefer a GUI the \fBcmake\fP line in the above example can
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   169
be replaced with:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   170
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   171
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   172
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   173
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   174
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   175
cmake\-gui ..
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   176
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   177
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   178
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   179
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   180
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   181
For command line help (including a list of available generators)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   182
for \fI\%CMake\fP simply run:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   183
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   184
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   185
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   186
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   187
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   188
cmake
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   189
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   190
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   191
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   192
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   193
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   194
To list available \fI\%CMake\fP settings (and what they are currently set to)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   195
for the project, run:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   196
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   197
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   198
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   199
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   200
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   201
cmake \-LH ..
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   202
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   203
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   204
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   205
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   206
.SS Mac OSX (Xcode)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   207
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   208
If you prefer using Xcode instead of make files on OSX,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   209
do the following. (Use the same steps as
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   210
for \fIUnix\fP):
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   211
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   212
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   213
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   214
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   215
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   216
\&...
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   217
cmake \-G "Xcode" ..
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   218
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   219
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   220
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   221
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   222
.SS Additional CMake settings
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   223
.SS Shared library
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   224
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   225
By default the \fI\%CMake\fP project will generate build files for building the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   226
static library. To build the shared version use:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   227
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   228
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   229
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   230
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   231
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   232
\&...
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   233
cmake \-DJANSSON_BUILD_SHARED_LIBS=1 ..
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   234
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   235
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   236
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   237
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   238
.SS Changing install directory (same as autoconf \-\-prefix)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   239
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   240
Just as with the \fI\%autoconf\fP project you can change the destination directory
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   241
for \fBmake install\fP\&. The equivalent for autoconfs \fB\&./configure \-\-prefix\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   242
in \fI\%CMake\fP is:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   243
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   244
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   245
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   246
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   247
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   248
\&...
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   249
cmake \-DCMAKE_INSTALL_PREFIX:PATH=/some/other/path ..
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   250
make install
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   251
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   252
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   253
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   254
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   255
.SS Android
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   256
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   257
Jansson can be built for Android platforms. Android.mk is in the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   258
source root directory. The configuration header file is located in the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   259
\fBandroid\fP directory in the source distribution.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   260
.SS Other Systems
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   261
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   262
On non Unix\-like systems, you may be unable to run the \fB\&./configure\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   263
script. In this case, follow these steps. All the files mentioned can
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   264
be found in the \fBsrc/\fP directory.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   265
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   266
.IP 1. 3
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   267
Create \fBjansson_config.h\fP (which has some platform\-specific
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   268
parameters that are normally filled in by the \fB\&./configure\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   269
script). Edit \fBjansson_config.h.in\fP, replacing all \fB@variable@\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   270
placeholders, and rename the file to \fBjansson_config.h\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   271
.IP 2. 3
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   272
Make \fBjansson.h\fP and \fBjansson_config.h\fP available to the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   273
compiler, so that they can be found when compiling programs that
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   274
use Jansson.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   275
.IP 3. 3
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   276
Compile all the \fB\&.c\fP files (in the \fBsrc/\fP directory) into a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   277
library file. Make the library available to the compiler, as in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   278
step 2.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   279
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   280
.SS Building the Documentation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   281
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   282
(This subsection describes how to build the HTML documentation you are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   283
currently reading, so it can be safely skipped.)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   284
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   285
Documentation is in the \fBdoc/\fP subdirectory. It\(aqs written in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   286
\fI\%reStructuredText\fP with \fI\%Sphinx\fP annotations. To generate the HTML
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   287
documentation, invoke:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   288
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   289
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   290
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   291
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   292
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   293
make html
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   294
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   295
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   296
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   297
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   298
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   299
and point your browser to \fBdoc/_build/html/index.html\fP\&. \fI\%Sphinx\fP 1.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   300
or newer is required to generate the documentation.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   301
.SS Compiling Programs that Use Jansson
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   302
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   303
Jansson involves one C header file, \fBjansson.h\fP, so it\(aqs enough
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   304
to put the line
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   305
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   306
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   307
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   308
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   309
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   310
#include <jansson.h>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   311
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   312
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   313
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   314
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   315
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   316
in the beginning of every source file that uses Jansson.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   317
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   318
There\(aqs also just one library to link with, \fBlibjansson\fP\&. Compile and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   319
link the program as follows:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   320
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   321
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   322
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   323
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   324
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   325
cc \-I/usr/include/jansson \-o prog prog.c \-ljansson
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   326
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   327
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   328
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   329
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   330
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   331
Starting from version 1.2, there\(aqs also support for \fI\%pkg\-config\fP:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   332
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   333
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   334
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   335
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   336
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   337
cc \-o prog prog.c \(gapkg\-config \-\-cflags \-\-libs jansson\(ga
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   338
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   339
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   340
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   341
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   342
.SS Upgrading from 1.x
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   343
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   344
This chapter lists the backwards incompatible changes introduced in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   345
Jansson 2.0, and the steps that are needed for upgrading your code.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   346
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   347
\fBThe incompatibilities are not dramatic.\fP The biggest change is that
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   348
all decoding functions now require and extra parameter. Most programs
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   349
can be modified to work with 2.0 by adding a \fB0\fP as the second
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   350
parameter to all calls of \fBjson_loads()\fP, \fBjson_loadf()\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   351
and \fBjson_load_file()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   352
.SS Compatibility
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   353
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   354
Jansson 2.0 is backwards incompatible with the Jansson 1.x releases.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   355
It is ABI incompatible, i.e. all programs dynamically linking to the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   356
Jansson library need to be recompiled. It\(aqs also API incompatible,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   357
i.e. the source code of programs using Jansson 1.x may need
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   358
modifications to make them compile against Jansson 2.0.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   359
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   360
All the 2.x releases are guaranteed to be backwards compatible for
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   361
both ABI and API, so no recompilation or source changes are needed
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   362
when upgrading from 2.x to 2.y.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   363
.SS List of Incompatible Changes
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   364
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   365
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   366
.B \fBDecoding flags\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   367
For future needs, a \fBflags\fP parameter was added as the second
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   368
parameter to all decoding functions, i.e. \fBjson_loads()\fP,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   369
\fBjson_loadf()\fP and \fBjson_load_file()\fP\&. All calls to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   370
these functions need to be changed by adding a \fB0\fP as the second
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   371
argument. For example:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   372
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   373
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   374
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   375
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   376
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   377
/* old code */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   378
json_loads(input, &error);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   379
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   380
/* new code */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   381
json_loads(input, 0, &error);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   382
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   383
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   384
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   385
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   386
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   387
.B \fBUnderlying type of JSON integers\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   388
The underlying C type of JSON integers has been changed from
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   389
\fBint\fP to the widest available signed integer type, i.e.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   390
\fBlong long\fP or \fBlong\fP, depending on whether
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   391
\fBlong long\fP is supported on your system or not. This makes
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   392
the whole 64\-bit integer range available on most modern systems.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   393
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   394
\fBjansson.h\fP has a typedef \fBjson_int_t\fP to the underlying
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   395
integer type. \fBint\fP should still be used in most cases when
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   396
dealing with smallish JSON integers, as the compiler handles
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   397
implicit type coercion. Only when the full 64\-bit range is needed,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   398
\fBjson_int_t\fP should be explicitly used.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   399
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   400
.B \fBMaximum encoder indentation depth\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   401
The maximum argument of the \fBJSON_INDENT()\fP macro has been
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   402
changed from 255 to 31, to free up bits from the \fBflags\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   403
parameter of \fBjson_dumps()\fP, \fBjson_dumpf()\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   404
\fBjson_dump_file()\fP\&. If your code uses a bigger indentation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   405
than 31, it needs to be changed.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   406
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   407
.B \fBUnsigned integers in API functions\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   408
Version 2.0 unifies unsigned integer usage in the API. All uses of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   409
\fBunsigned int\fP and \fBunsigned long\fP have been replaced
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   410
with \fBsize_t\fP\&. This includes flags, container sizes, etc.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   411
This should not require source code changes, as both
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   412
\fBunsigned int\fP and \fBunsigned long\fP are usually
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   413
compatible with \fBsize_t\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   414
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   415
.SS Tutorial
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   416
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   417
In this tutorial, we create a program that fetches the latest commits
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   418
of a repository in \fI\%GitHub\fP over the web. \fI\%GitHub API\fP uses JSON, so
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   419
the result can be parsed using Jansson.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   420
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   421
To stick to the the scope of this tutorial, we will only cover the the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   422
parts of the program related to handling JSON data. For the best user
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   423
experience, the full source code is available:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   424
\fBgithub_commits.c\fP\&. To compile it (on Unix\-like systems with
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   425
gcc), use the following command:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   426
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   427
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   428
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   429
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   430
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   431
gcc \-o github_commits github_commits.c \-ljansson \-lcurl
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   432
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   433
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   434
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   435
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   436
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   437
\fI\%libcurl\fP is used to communicate over the web, so it is required to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   438
compile the program.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   439
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   440
The command line syntax is:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   441
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   442
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   443
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   444
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   445
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   446
github_commits USER REPOSITORY
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   447
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   448
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   449
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   450
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   451
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   452
\fBUSER\fP is a GitHub user ID and \fBREPOSITORY\fP is the repository
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   453
name. Please note that the GitHub API is rate limited, so if you run
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   454
the program too many times within a short period of time, the sever
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   455
starts to respond with an error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   456
.SS The GitHub Repo Commits API
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   457
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   458
The \fI\%GitHub Repo Commits API\fP is used by sending HTTP requests to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   459
URLs like \fBhttps://api.github.com/repos/USER/REPOSITORY/commits\fP,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   460
where \fBUSER\fP and \fBREPOSITORY\fP are the GitHub user ID and the name
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   461
of the repository whose commits are to be listed, respectively.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   462
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   463
GitHub responds with a JSON array of the following form:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   464
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   465
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   466
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   467
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   468
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   469
[
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   470
    {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   471
        "sha": "<the commit ID>",
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   472
        "commit": {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   473
            "message": "<the commit message>",
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   474
            <more fields, not important to this tutorial...>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   475
        },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   476
        <more fields...>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   477
    },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   478
    {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   479
        "sha": "<the commit ID>",
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   480
        "commit": {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   481
            "message": "<the commit message>",
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   482
            <more fields...>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   483
        },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   484
        <more fields...>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   485
    },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   486
    <more commits...>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   487
]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   488
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   489
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   490
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   491
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   492
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   493
In our program, the HTTP request is sent using the following
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   494
function:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   495
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   496
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   497
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   498
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   499
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   500
static char *request(const char *url);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   501
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   502
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   503
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   504
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   505
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   506
It takes the URL as a parameter, preforms a HTTP GET request, and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   507
returns a newly allocated string that contains the response body. If
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   508
the request fails, an error message is printed to stderr and the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   509
return value is \fINULL\fP\&. For full details, refer to \fBthe code\fP, as the actual implementation is not important
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   510
here.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   511
.SS The Program
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   512
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   513
First the includes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   514
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   515
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   516
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   517
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   518
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   519
#include <string.h>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   520
#include <jansson.h>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   521
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   522
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   523
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   524
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   525
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   526
Like all the programs using Jansson, we need to include
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   527
\fBjansson.h\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   528
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   529
The following definitions are used to build the GitHub API request
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   530
URL:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   531
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   532
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   533
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   534
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   535
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   536
#define URL_FORMAT   "https://api.github.com/repos/%s/%s/commits"
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   537
#define URL_SIZE     256
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   538
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   539
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   540
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   541
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   542
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   543
The following function is used when formatting the result to find the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   544
first newline in the commit message:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   545
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   546
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   547
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   548
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   549
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   550
/* Return the offset of the first newline in text or the length of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   551
   text if there\(aqs no newline */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   552
static int newline_offset(const char *text)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   553
{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   554
    const char *newline = strchr(text, \(aq\en\(aq);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   555
    if(!newline)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   556
        return strlen(text);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   557
    else
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   558
        return (int)(newline \- text);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   559
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   560
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   561
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   562
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   563
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   564
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   565
The main function follows. In the beginning, we first declare a bunch
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   566
of variables and check the command line parameters:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   567
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   568
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   569
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   570
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   571
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   572
int main(int argc, char *argv[])
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   573
{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   574
    size_t i;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   575
    char *text;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   576
    char url[URL_SIZE];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   577
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   578
    json_t *root;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   579
    json_error_t error;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   580
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   581
    if(argc != 3)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   582
    {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   583
        fprintf(stderr, "usage: %s USER REPOSITORY\en\en", argv[0]);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   584
        fprintf(stderr, "List commits at USER\(aqs REPOSITORY.\en\en");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   585
        return 2;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   586
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   587
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   588
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   589
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   590
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   591
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   592
Then we build the request URL using the user and repository names
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   593
given as command line parameters:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   594
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   595
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   596
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   597
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   598
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   599
snprintf(url, URL_SIZE, URL_FORMAT, argv[1], argv[2]);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   600
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   601
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   602
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   603
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   604
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   605
This uses the \fBURL_SIZE\fP and \fBURL_FORMAT\fP constants defined above.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   606
Now we\(aqre ready to actually request the JSON data over the web:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   607
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   608
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   609
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   610
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   611
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   612
text = request(url);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   613
if(!text)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   614
    return 1;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   615
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   616
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   617
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   618
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   619
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   620
If an error occurs, our function \fBrequest\fP prints the error and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   621
returns \fINULL\fP, so it\(aqs enough to just return 1 from the main
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   622
function.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   623
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   624
Next we\(aqll call \fBjson_loads()\fP to decode the JSON text we got
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   625
as a response:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   626
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   627
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   628
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   629
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   630
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   631
root = json_loads(text, 0, &error);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   632
free(text);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   633
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   634
if(!root)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   635
{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   636
    fprintf(stderr, "error: on line %d: %s\en", error.line, error.text);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   637
    return 1;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   638
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   639
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   640
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   641
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   642
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   643
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   644
We don\(aqt need the JSON text anymore, so we can free the \fBtext\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   645
variable right after decoding it. If \fBjson_loads()\fP fails, it
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   646
returns \fINULL\fP and sets error information to the \fBjson_error_t\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   647
structure given as the second parameter. In this case, our program
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   648
prints the error information out and returns 1 from the main function.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   649
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   650
Now we\(aqre ready to extract the data out of the decoded JSON response.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   651
The structure of the response JSON was explained in section
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   652
\fI\%The GitHub Repo Commits API\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   653
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   654
We check that the returned value really is an array:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   655
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   656
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   657
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   658
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   659
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   660
if(!json_is_array(root))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   661
{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   662
    fprintf(stderr, "error: root is not an array\en");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   663
    json_decref(root);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   664
    return 1;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   665
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   666
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   667
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   668
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   669
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   670
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   671
Then we proceed to loop over all the commits in the array:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   672
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   673
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   674
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   675
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   676
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   677
for(i = 0; i < json_array_size(root); i++)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   678
{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   679
    json_t *data, *sha, *commit, *message;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   680
    const char *message_text;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   681
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   682
    data = json_array_get(root, i);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   683
    if(!json_is_object(data))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   684
    {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   685
        fprintf(stderr, "error: commit data %d is not an object\en", i + 1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   686
        json_decref(root);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   687
        return 1;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   688
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   689
\&...
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   690
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   691
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   692
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   693
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   694
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   695
The function \fBjson_array_size()\fP returns the size of a JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   696
array. First, we again declare some variables and then extract the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   697
i\(aqth element of the \fBroot\fP array using \fBjson_array_get()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   698
We also check that the resulting value is a JSON object.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   699
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   700
Next we\(aqll extract the commit ID (a hexadecimal SHA\-1 sum),
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   701
intermediate commit info object, and the commit message from that
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   702
object. We also do proper type checks:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   703
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   704
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   705
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   706
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   707
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   708
    sha = json_object_get(data, "sha");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   709
    if(!json_is_string(sha))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   710
    {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   711
        fprintf(stderr, "error: commit %d: sha is not a string\en", i + 1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   712
        json_decref(root);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   713
        return 1;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   714
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   715
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   716
    commit = json_object_get(data, "commit");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   717
    if(!json_is_object(commit))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   718
    {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   719
        fprintf(stderr, "error: commit %d: commit is not an object\en", i + 1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   720
        json_decref(root);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   721
        return 1;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   722
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   723
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   724
    message = json_object_get(commit, "message");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   725
    if(!json_is_string(message))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   726
    {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   727
        fprintf(stderr, "error: commit %d: message is not a string\en", i + 1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   728
        json_decref(root);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   729
        return 1;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   730
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   731
\&...
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   732
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   733
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   734
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   735
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   736
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   737
And finally, we\(aqll print the first 8 characters of the commit ID and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   738
the first line of the commit message. A C\-style string is extracted
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   739
from a JSON string using \fBjson_string_value()\fP:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   740
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   741
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   742
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   743
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   744
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   745
    message_text = json_string_value(message);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   746
    printf("%.8s %.*s\en",
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   747
           json_string_value(id),
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   748
           newline_offset(message_text),
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   749
           message_text);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   750
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   751
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   752
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   753
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   754
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   755
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   756
After sending the HTTP request, we decoded the JSON text using
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   757
\fBjson_loads()\fP, remember? It returns a \fInew reference\fP to the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   758
JSON value it decodes. When we\(aqre finished with the value, we\(aqll need
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   759
to decrease the reference count using \fBjson_decref()\fP\&. This way
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   760
Jansson can release the resources:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   761
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   762
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   763
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   764
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   765
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   766
json_decref(root);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   767
return 0;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   768
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   769
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   770
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   771
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   772
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   773
For a detailed explanation of reference counting in Jansson, see
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   774
\fIapiref\-reference\-count\fP in \fIapiref\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   775
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   776
The program\(aqs ready, let\(aqs test it and view the latest commits in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   777
Jansson\(aqs repository:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   778
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   779
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   780
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   781
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   782
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   783
$ ./github_commits akheron jansson
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   784
1581f26a Merge branch \(aq2.3\(aq
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   785
aabfd493 load: Change buffer_pos to be a size_t
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   786
bd72efbd load: Avoid unexpected behaviour in macro expansion
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   787
e8fd3e30 Document and tweak json_load_callback()
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   788
873eddaf Merge pull request #60 from rogerz/contrib
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   789
bd2c0c73 Ignore the binary test_load_callback
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   790
17a51a4b Merge branch \(aq2.3\(aq
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   791
09c39adc Add json_load_callback to the list of exported symbols
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   792
cbb80baf Merge pull request #57 from rogerz/contrib
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   793
040bd7b0 Add json_load_callback()
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   794
2637faa4 Make test stripping locale independent
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   795
<...>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   796
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   797
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   798
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   799
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   800
.SS Conclusion
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   801
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   802
In this tutorial, we implemented a program that fetches the latest
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   803
commits of a GitHub repository using the GitHub Repo Commits API.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   804
Jansson was used to decode the JSON response and to extract the commit
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   805
data.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   806
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   807
This tutorial only covered a small part of Jansson. For example, we
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   808
did not create or manipulate JSON values at all. Proceed to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   809
\fIapiref\fP to explore all features of Jansson.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   810
.SS RFC Conformance
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   811
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   812
JSON is specified in \fI\%RFC 4627\fP, \fI"The application/json Media Type
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   813
for JavaScript Object Notation (JSON)"\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   814
.SS Character Encoding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   815
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   816
Jansson only supports UTF\-8 encoded JSON texts. It does not support or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   817
auto\-detect any of the other encodings mentioned in the RFC, namely
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   818
UTF\-16LE, UTF\-16BE, UTF\-32LE or UTF\-32BE. Pure ASCII is supported, as
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   819
it\(aqs a subset of UTF\-8.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   820
.SS Strings
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   821
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   822
JSON strings are mapped to C\-style null\-terminated character arrays,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   823
and UTF\-8 encoding is used internally.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   824
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   825
All Unicode codepoints U+0000 through U+10FFFF are allowed in string
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   826
values. However, U+0000 is not allowed in object keys because of API
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   827
restrictions.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   828
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   829
Unicode normalization or any other transformation is never performed
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   830
on any strings (string values or object keys). When checking for
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   831
equivalence of strings or object keys, the comparison is performed
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   832
byte by byte between the original UTF\-8 representations of the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   833
strings.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   834
.SS Numbers
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   835
.SS Real vs. Integer
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   836
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   837
JSON makes no distinction between real and integer numbers; Jansson
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   838
does. Real numbers are mapped to the \fBdouble\fP type and integers to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   839
the \fBjson_int_t\fP type, which is a typedef of \fBlong long\fP or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   840
\fBlong\fP, depending on whether \fBlong long\fP is supported by your
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   841
compiler or not.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   842
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   843
A JSON number is considered to be a real number if its lexical
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   844
representation includes one of \fBe\fP, \fBE\fP, or \fB\&.\fP; regardless if
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   845
its actual numeric value is a true integer (e.g., all of \fB1E6\fP,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   846
\fB3.0\fP, \fB400E\-2\fP, and \fB3.14E3\fP are mathematical integers, but
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   847
will be treated as real values). With the \fBJSON_DECODE_INT_AS_REAL\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   848
decoder flag set all numbers are interpreted as real.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   849
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   850
All other JSON numbers are considered integers.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   851
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   852
When encoding to JSON, real values are always represented
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   853
with a fractional part; e.g., the \fBdouble\fP value 3.0 will be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   854
represented in JSON as \fB3.0\fP, not \fB3\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   855
.SS Overflow, Underflow & Precision
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   856
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   857
Real numbers whose absolute values are too small to be represented in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   858
a C \fBdouble\fP will be silently estimated with 0.0. Thus, depending on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   859
platform, JSON numbers very close to zero such as 1E\-999 may result in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   860
0.0.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   861
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   862
Real numbers whose absolute values are too large to be represented in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   863
a C \fBdouble\fP will result in an overflow error (a JSON decoding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   864
error). Thus, depending on platform, JSON numbers like 1E+999 or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   865
\-1E+999 may result in a parsing error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   866
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   867
Likewise, integer numbers whose absolute values are too large to be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   868
represented in the \fBjson_int_t\fP type (see above) will result in an
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   869
overflow error (a JSON decoding error). Thus, depending on platform,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   870
JSON numbers like 1000000000000000 may result in parsing error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   871
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   872
Parsing JSON real numbers may result in a loss of precision. As long
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   873
as overflow does not occur (i.e. a total loss of precision), the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   874
rounded approximate value is silently used. Thus the JSON number
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   875
1.000000000000000005 may, depending on platform, result in the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   876
\fBdouble\fP value 1.0.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   877
.SS Signed zeros
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   878
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   879
JSON makes no statement about what a number means; however Javascript
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   880
(ECMAscript) does state that +0.0 and \-0.0 must be treated as being
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   881
distinct values, i.e. \-0.0 ≠ 0.0. Jansson relies on the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   882
underlying floating point library in the C environment in which it is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   883
compiled. Therefore it is platform\-dependent whether 0.0 and \-0.0 will
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   884
be distinct values. Most platforms that use the IEEE 754
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   885
floating\-point standard will support signed zeros.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   886
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   887
Note that this only applies to floating\-point; neither JSON, C, or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   888
IEEE support the concept of signed integer zeros.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   889
.SS Types
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   890
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   891
No support is provided in Jansson for any C numeric types other than
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   892
\fBjson_int_t\fP and \fBdouble\fP\&. This excludes things such as unsigned
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   893
types, \fBlong double\fP, etc. Obviously, shorter types like \fBshort\fP,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   894
\fBint\fP, \fBlong\fP (if \fBjson_int_t\fP is \fBlong long\fP) and \fBfloat\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   895
are implicitly handled via the ordinary C type coercion rules (subject
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   896
to overflow semantics). Also, no support or hooks are provided for any
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   897
supplemental "bignum" type add\-on packages.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   898
.SS Portability
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   899
.SS Thread safety
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   900
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   901
Jansson is thread safe and has no mutable global state. The only
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   902
exceptions are the hash function seed and memory allocation functions,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   903
see below.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   904
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   905
There\(aqs no locking performed inside Jansson\(aqs code, so a multithreaded
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   906
program must perform its own locking if JSON values are shared by
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   907
multiple threads. Jansson\(aqs reference counting semantics may make this
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   908
a bit harder than it seems, as it\(aqs possible to have a reference to a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   909
value that\(aqs also stored inside a list or object. Modifying the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   910
container (adding or removing values) may trigger concurrent access to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   911
such values, as containers manage the reference count of their
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   912
contained values. Bugs involving concurrent incrementing or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   913
decrementing of deference counts may be hard to track.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   914
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   915
The encoding functions (\fBjson_dumps()\fP and friends) track
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   916
reference loops by modifying the internal state of objects and arrays.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   917
For this reason, encoding functions must not be run on the same JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   918
values in two separate threads at the same time. As already noted
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   919
above, be especially careful if two arrays or objects share their
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   920
contained values with another array or object.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   921
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   922
If you want to make sure that two JSON value hierarchies do not
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   923
contain shared values, use \fBjson_deep_copy()\fP to make copies.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   924
.SS Hash function seed
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   925
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   926
To prevent an attacker from intentionally causing large JSON objects
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   927
with specially crafted keys to perform very slow, the hash function
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   928
used by Jansson is randomized using a seed value. The seed is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   929
automatically generated on the first explicit or implicit call to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   930
\fBjson_object()\fP, if \fBjson_object_seed()\fP has not been
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   931
called beforehand.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   932
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   933
The seed is generated by using operating system\(aqs entropy sources if
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   934
they are available (\fB/dev/urandom\fP, \fBCryptGenRandom()\fP). The
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   935
initialization is done in as thread safe manner as possible, by using
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   936
architecture specific lockless operations if provided by the platform
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   937
or the compiler.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   938
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   939
If you\(aqre using threads, it\(aqs recommended to autoseed the hashtable
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   940
explicitly before spawning any threads by calling
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   941
\fBjson_object_seed(0)\fP , especially if you\(aqre unsure whether the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   942
initialization is thread safe on your platform.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   943
.SS Memory allocation functions
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   944
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   945
Memory allocation functions should be set at most once, and only on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   946
program startup. See \fIapiref\-custom\-memory\-allocation\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   947
.SS Locale
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   948
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   949
Jansson works fine under any locale.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   950
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   951
However, if the host program is multithreaded and uses \fBsetlocale()\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   952
to switch the locale in one thread while Jansson is currently encoding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   953
or decoding JSON data in another thread, the result may be wrong or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   954
the program may even crash.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   955
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   956
Jansson uses locale specific functions for certain string conversions
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   957
in the encoder and decoder, and then converts the locale specific
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   958
values to/from the JSON representation. This fails if the locale
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   959
changes between the string conversion and the locale\-to\-JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   960
conversion. This can only happen in multithreaded programs that use
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   961
\fBsetlocale()\fP, because \fBsetlocale()\fP switches the locale for all
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   962
running threads, not only the thread that calls \fBsetlocale()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   963
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   964
If your program uses \fBsetlocale()\fP as described above, consider
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   965
using the thread\-safe \fBuselocale()\fP instead.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   966
.SS API Reference
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   967
.SS Preliminaries
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   968
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   969
All declarations are in \fBjansson.h\fP, so it\(aqs enough to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   970
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   971
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   972
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   973
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   974
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   975
#include <jansson.h>
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   976
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   977
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   978
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   979
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   980
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   981
in each source file.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   982
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   983
All constants are prefixed with \fBJSON_\fP (except for those describing
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   984
the library version, prefixed with \fBJANSSON_\fP). Other identifiers
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   985
are prefixed with \fBjson_\fP\&. Type names are suffixed with \fB_t\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   986
\fBtypedef\fP\(aqd so that the \fBstruct\fP keyword need not be used.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   987
.SS Library Version
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   988
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   989
The Jansson version is of the form \fIA.B.C\fP, where \fIA\fP is the major
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   990
version, \fIB\fP is the minor version and \fIC\fP is the micro version. If the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   991
micro version is zero, it\(aqs omitted from the version string, i.e. the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   992
version string is just \fIA.B\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   993
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   994
When a new release only fixes bugs and doesn\(aqt add new features or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   995
functionality, the micro version is incremented. When new features are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   996
added in a backwards compatible way, the minor version is incremented
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   997
and the micro version is set to zero. When there are backwards
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   998
incompatible changes, the major version is incremented and others are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   999
set to zero.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1000
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1001
The following preprocessor constants specify the current version of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1002
the library:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1003
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1004
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1005
.B \fBJANSSON_MAJOR_VERSION\fP, \fBJANSSON_MINOR_VERSION\fP, \fBJANSSON_MICRO_VERSION\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1006
Integers specifying the major, minor and micro versions,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1007
respectively.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1008
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1009
.B \fBJANSSON_VERSION\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1010
A string representation of the current version, e.g. \fB"1.2.1"\fP or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1011
\fB"1.3"\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1012
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1013
.B \fBJANSSON_VERSION_HEX\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1014
A 3\-byte hexadecimal representation of the version, e.g.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1015
\fB0x010201\fP for version 1.2.1 and \fB0x010300\fP for version 1.3.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1016
This is useful in numeric comparisions, e.g.:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1017
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1018
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1019
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1020
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1021
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1022
#if JANSSON_VERSION_HEX >= 0x010300
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1023
/* Code specific to version 1.3 and above */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1024
#endif
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1025
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1026
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1027
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1028
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1029
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1030
.SS Value Representation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1031
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1032
The JSON specification (\fI\%RFC 4627\fP) defines the following data types:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1033
\fIobject\fP, \fIarray\fP, \fIstring\fP, \fInumber\fP, \fIboolean\fP, and \fInull\fP\&. JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1034
types are used dynamically; arrays and objects can hold any other data
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1035
type, including themselves. For this reason, Jansson\(aqs type system is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1036
also dynamic in nature. There\(aqs one C type to represent all JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1037
values, and this structure knows the type of the JSON value it holds.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1038
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1039
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1040
.B json_t
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1041
This data structure is used throughout the library to represent all
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1042
JSON values. It always contains the type of the JSON value it holds
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1043
and the value\(aqs reference count. The rest depends on the type of the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1044
value.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1045
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1046
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1047
Objects of \fBjson_t\fP are always used through a pointer. There
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1048
are APIs for querying the type, manipulating the reference count, and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1049
for constructing and manipulating values of different types.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1050
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1051
Unless noted otherwise, all API functions return an error value if an
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1052
error occurs. Depending on the function\(aqs signature, the error value
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1053
is either \fINULL\fP or \-1. Invalid arguments or invalid input are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1054
apparent sources for errors. Memory allocation and I/O operations may
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1055
also cause errors.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1056
.SS Type
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1057
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1058
The type of a JSON value is queried and tested using the following
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1059
functions:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1060
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1061
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1062
.B enum json_type
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1063
The type of a JSON value. The following members are defined:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1064
.TS
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1065
center;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1066
|l|.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1067
_
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1068
T{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1069
\fBJSON_OBJECT\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1070
T}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1071
_
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1072
T{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1073
\fBJSON_ARRAY\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1074
T}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1075
_
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1076
T{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1077
\fBJSON_STRING\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1078
T}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1079
_
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1080
T{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1081
\fBJSON_INTEGER\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1082
T}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1083
_
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1084
T{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1085
\fBJSON_REAL\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1086
T}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1087
_
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1088
T{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1089
\fBJSON_TRUE\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1090
T}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1091
_
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1092
T{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1093
\fBJSON_FALSE\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1094
T}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1095
_
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1096
T{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1097
\fBJSON_NULL\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1098
T}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1099
_
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1100
.TE
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1101
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1102
These correspond to JSON object, array, string, number, boolean and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1103
null. A number is represented by either a value of the type
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1104
\fBJSON_INTEGER\fP or of the type \fBJSON_REAL\fP\&. A true boolean value
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1105
is represented by a value of the type \fBJSON_TRUE\fP and false by a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1106
value of the type \fBJSON_FALSE\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1107
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1108
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1109
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1110
.B int json_typeof(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1111
Return the type of the JSON value (a \fBjson_type\fP cast to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1112
\fBint\fP). \fIjson\fP MUST NOT be \fINULL\fP\&. This function is actually
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1113
implemented as a macro for speed.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1114
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1115
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1116
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1117
.B json_is_object(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1118
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1119
.B json_is_array(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1120
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1121
.B json_is_string(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1122
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1123
.B json_is_integer(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1124
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1125
.B json_is_real(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1126
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1127
.B json_is_true(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1128
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1129
.B json_is_false(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1130
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1131
.B json_is_null(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1132
These functions (actually macros) return true (non\-zero) for values
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1133
of the given type, and false (zero) for values of other types and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1134
for \fINULL\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1135
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1136
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1137
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1138
.B json_is_number(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1139
Returns true for values of types \fBJSON_INTEGER\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1140
\fBJSON_REAL\fP, and false for other types and for \fINULL\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1141
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1142
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1143
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1144
.B json_is_boolean(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1145
Returns true for types \fBJSON_TRUE\fP and \fBJSON_FALSE\fP, and false
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1146
for values of other types and for \fINULL\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1147
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1148
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1149
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1150
.B json_boolean_value(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1151
Alias of \fBjson_is_true()\fP, i.e. returns 1 for \fBJSON_TRUE\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1152
and 0 otherwise.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1153
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1154
New in version 2.7.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1155
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1156
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1157
.SS Reference Count
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1158
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1159
The reference count is used to track whether a value is still in use
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1160
or not. When a value is created, it\(aqs reference count is set to 1. If
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1161
a reference to a value is kept (e.g. a value is stored somewhere for
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1162
later use), its reference count is incremented, and when the value is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1163
no longer needed, the reference count is decremented. When the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1164
reference count drops to zero, there are no references left, and the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1165
value can be destroyed.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1166
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1167
The following functions are used to manipulate the reference count.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1168
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1169
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1170
.B json_t *json_incref(json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1171
Increment the reference count of \fIjson\fP if it\(aqs not \fINULL\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1172
Returns \fIjson\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1173
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1174
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1175
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1176
.B void json_decref(json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1177
Decrement the reference count of \fIjson\fP\&. As soon as a call to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1178
\fBjson_decref()\fP drops the reference count to zero, the value
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1179
is destroyed and it can no longer be used.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1180
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1181
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1182
Functions creating new JSON values set the reference count to 1. These
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1183
functions are said to return a \fBnew reference\fP\&. Other functions
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1184
returning (existing) JSON values do not normally increase the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1185
reference count. These functions are said to return a \fBborrowed
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1186
reference\fP\&. So, if the user will hold a reference to a value returned
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1187
as a borrowed reference, he must call \fBjson_incref()\fP\&. As soon as
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1188
the value is no longer needed, \fBjson_decref()\fP should be called
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1189
to release the reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1190
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1191
Normally, all functions accepting a JSON value as an argument will
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1192
manage the reference, i.e. increase and decrease the reference count
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1193
as needed. However, some functions \fBsteal\fP the reference, i.e. they
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1194
have the same result as if the user called \fBjson_decref()\fP on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1195
the argument right after calling the function. These functions are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1196
suffixed with \fB_new\fP or have \fB_new_\fP somewhere in their name.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1197
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1198
For example, the following code creates a new JSON array and appends
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1199
an integer to it:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1200
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1201
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1202
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1203
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1204
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1205
json_t *array, *integer;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1206
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1207
array = json_array();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1208
integer = json_integer(42);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1209
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1210
json_array_append(array, integer);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1211
json_decref(integer);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1212
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1213
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1214
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1215
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1216
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1217
Note how the caller has to release the reference to the integer value
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1218
by calling \fBjson_decref()\fP\&. By using a reference stealing
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1219
function \fBjson_array_append_new()\fP instead of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1220
\fBjson_array_append()\fP, the code becomes much simpler:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1221
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1222
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1223
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1224
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1225
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1226
json_t *array = json_array();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1227
json_array_append_new(array, json_integer(42));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1228
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1229
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1230
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1231
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1232
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1233
In this case, the user doesn\(aqt have to explicitly release the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1234
reference to the integer value, as \fBjson_array_append_new()\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1235
steals the reference when appending the value to the array.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1236
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1237
In the following sections it is clearly documented whether a function
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1238
will return a new or borrowed reference or steal a reference to its
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1239
argument.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1240
.SS Circular References
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1241
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1242
A circular reference is created when an object or an array is,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1243
directly or indirectly, inserted inside itself. The direct case is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1244
simple:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1245
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1246
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1247
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1248
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1249
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1250
json_t *obj = json_object();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1251
json_object_set(obj, "foo", obj);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1252
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1253
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1254
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1255
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1256
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1257
Jansson will refuse to do this, and \fBjson_object_set()\fP (and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1258
all the other such functions for objects and arrays) will return with
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1259
an error status. The indirect case is the dangerous one:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1260
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1261
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1262
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1263
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1264
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1265
json_t *arr1 = json_array(), *arr2 = json_array();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1266
json_array_append(arr1, arr2);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1267
json_array_append(arr2, arr1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1268
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1269
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1270
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1271
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1272
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1273
In this example, the array \fBarr2\fP is contained in the array
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1274
\fBarr1\fP, and vice versa. Jansson cannot check for this kind of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1275
indirect circular references without a performance hit, so it\(aqs up to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1276
the user to avoid them.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1277
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1278
If a circular reference is created, the memory consumed by the values
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1279
cannot be freed by \fBjson_decref()\fP\&. The reference counts never
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1280
drops to zero because the values are keeping the references to each
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1281
other. Moreover, trying to encode the values with any of the encoding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1282
functions will fail. The encoder detects circular references and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1283
returns an error status.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1284
.SS True, False and Null
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1285
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1286
These three values are implemented as singletons, so the returned
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1287
pointers won\(aqt change between invocations of these functions.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1288
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1289
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1290
.B json_t *json_true(void)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1291
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1292
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1293
Returns the JSON true value.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1294
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1295
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1296
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1297
.B json_t *json_false(void)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1298
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1299
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1300
Returns the JSON false value.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1301
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1302
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1303
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1304
.B json_t *json_boolean(val)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1305
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1306
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1307
Returns JSON false if \fBval\fP is zero, and JSON true otherwise.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1308
This is a macro, and equivalent to \fBval ? json_true() :
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1309
json_false()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1310
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1311
New in version 2.4.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1312
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1313
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1314
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1315
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1316
.B json_t *json_null(void)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1317
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1318
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1319
Returns the JSON null value.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1320
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1321
.SS String
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1322
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1323
Jansson uses UTF\-8 as the character encoding. All JSON strings must be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1324
valid UTF\-8 (or ASCII, as it\(aqs a subset of UTF\-8). All Unicode
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1325
codepoints U+0000 through U+10FFFF are allowed, but you must use
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1326
length\-aware functions if you wish to embed NUL bytes in strings.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1327
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1328
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1329
.B json_t *json_string(const char\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1330
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1331
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1332
Returns a new JSON string, or \fINULL\fP on error. \fIvalue\fP must be a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1333
valid null terminated UTF\-8 encoded Unicode string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1334
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1335
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1336
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1337
.B json_t *json_stringn(const char\fI\ *value\fP, size_t\fI\ len\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1338
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1339
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1340
Like \fBjson_string()\fP, but with explicit length, so \fIvalue\fP may
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1341
contain null characters or not be null terminated.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1342
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1343
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1344
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1345
.B json_t *json_string_nocheck(const char\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1346
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1347
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1348
Like \fBjson_string()\fP, but doesn\(aqt check that \fIvalue\fP is valid
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1349
UTF\-8. Use this function only if you are certain that this really
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1350
is the case (e.g. you have already checked it by other means).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1351
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1352
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1353
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1354
.B json_t *json_stringn_nocheck(const char\fI\ *value\fP, size_t\fI\ len\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1355
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1356
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1357
Like \fBjson_string_nocheck()\fP, but with explicit length, so
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1358
\fIvalue\fP may contain null characters or not be null terminated.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1359
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1360
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1361
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1362
.B const char *json_string_value(const json_t\fI\ *string\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1363
Returns the associated value of \fIstring\fP as a null terminated UTF\-8
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1364
encoded string, or \fINULL\fP if \fIstring\fP is not a JSON string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1365
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1366
The retuned value is read\-only and must not be modified or freed by
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1367
the user. It is valid as long as \fIstring\fP exists, i.e. as long as
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1368
its reference count has not dropped to zero.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1369
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1370
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1371
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1372
.B size_t json_string_length(const json_t\fI\ *string\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1373
Returns the length of \fIstring\fP in its UTF\-8 presentation, or zero
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1374
if \fIstring\fP is not a JSON string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1375
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1376
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1377
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1378
.B int json_string_set(const json_t\fI\ *string\fP, const char\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1379
Sets the associated value of \fIstring\fP to \fIvalue\fP\&. \fIvalue\fP must be a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1380
valid UTF\-8 encoded Unicode string. Returns 0 on success and \-1 on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1381
error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1382
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1383
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1384
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1385
.B int json_string_setn(json_t\fI\ *string\fP, const char\fI\ *value\fP, size_t\fI\ len\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1386
Like \fBjson_string_set()\fP, but with explicit length, so \fIvalue\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1387
may contain null characters or not be null terminated.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1388
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1389
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1390
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1391
.B int json_string_set_nocheck(const json_t\fI\ *string\fP, const char\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1392
Like \fBjson_string_set()\fP, but doesn\(aqt check that \fIvalue\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1393
valid UTF\-8. Use this function only if you are certain that this
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1394
really is the case (e.g. you have already checked it by other
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1395
means).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1396
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1397
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1398
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1399
.B int json_string_setn_nocheck(json_t\fI\ *string\fP, const char\fI\ *value\fP, size_t\fI\ len\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1400
Like \fBjson_string_set_nocheck()\fP, but with explicit length,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1401
so \fIvalue\fP may contain null characters or not be null terminated.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1402
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1403
.SS Number
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1404
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1405
The JSON specification only contains one numeric type, "number". The C
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1406
programming language has distinct types for integer and floating\-point
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1407
numbers, so for practical reasons Jansson also has distinct types for
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1408
the two. They are called "integer" and "real", respectively. For more
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1409
information, see \fIrfc\-conformance\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1410
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1411
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1412
.B json_int_t
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1413
This is the C type that is used to store JSON integer values. It
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1414
represents the widest integer type available on your system. In
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1415
practice it\(aqs just a typedef of \fBlong long\fP if your compiler
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1416
supports it, otherwise \fBlong\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1417
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1418
Usually, you can safely use plain \fBint\fP in place of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1419
\fBjson_int_t\fP, and the implicit C integer conversion handles the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1420
rest. Only when you know that you need the full 64\-bit range, you
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1421
should use \fBjson_int_t\fP explicitly.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1422
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1423
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1424
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1425
.B \fBJSON_INTEGER_IS_LONG_LONG\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1426
This is a preprocessor variable that holds the value 1 if
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1427
\fBjson_int_t\fP is \fBlong long\fP, and 0 if it\(aqs \fBlong\fP\&. It
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1428
can be used as follows:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1429
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1430
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1431
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1432
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1433
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1434
#if JSON_INTEGER_IS_LONG_LONG
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1435
/* Code specific for long long */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1436
#else
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1437
/* Code specific for long */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1438
#endif
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1439
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1440
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1441
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1442
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1443
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1444
.B \fBJSON_INTEGER_FORMAT\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1445
This is a macro that expands to a \fBprintf()\fP conversion
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1446
specifier that corresponds to \fBjson_int_t\fP, without the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1447
leading \fB%\fP sign, i.e. either \fB"lld"\fP or \fB"ld"\fP\&. This macro
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1448
is required because the actual type of \fBjson_int_t\fP can be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1449
either \fBlong\fP or \fBlong long\fP, and \fBprintf()\fP reuiqres
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1450
different length modifiers for the two.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1451
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1452
Example:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1453
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1454
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1455
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1456
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1457
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1458
json_int_t x = 123123123;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1459
printf("x is %" JSON_INTEGER_FORMAT "\en", x);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1460
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1461
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1462
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1463
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1464
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1465
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1466
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1467
.B json_t *json_integer(json_int_t\fI\ value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1468
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1469
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1470
Returns a new JSON integer, or \fINULL\fP on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1471
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1472
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1473
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1474
.B json_int_t json_integer_value(const json_t\fI\ *integer\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1475
Returns the associated value of \fIinteger\fP, or 0 if \fIjson\fP is not a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1476
JSON integer.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1477
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1478
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1479
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1480
.B int json_integer_set(const json_t\fI\ *integer\fP, json_int_t\fI\ value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1481
Sets the associated value of \fIinteger\fP to \fIvalue\fP\&. Returns 0 on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1482
success and \-1 if \fIinteger\fP is not a JSON integer.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1483
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1484
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1485
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1486
.B json_t *json_real(double\fI\ value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1487
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1488
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1489
Returns a new JSON real, or \fINULL\fP on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1490
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1491
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1492
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1493
.B double json_real_value(const json_t\fI\ *real\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1494
Returns the associated value of \fIreal\fP, or 0.0 if \fIreal\fP is not a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1495
JSON real.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1496
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1497
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1498
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1499
.B int json_real_set(const json_t\fI\ *real\fP, double\fI\ value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1500
Sets the associated value of \fIreal\fP to \fIvalue\fP\&. Returns 0 on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1501
success and \-1 if \fIreal\fP is not a JSON real.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1502
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1503
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1504
In addition to the functions above, there\(aqs a common query function
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1505
for integers and reals:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1506
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1507
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1508
.B double json_number_value(const json_t\fI\ *json\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1509
Returns the associated value of the JSON integer or JSON real
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1510
\fIjson\fP, cast to double regardless of the actual type. If \fIjson\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1511
neither JSON real nor JSON integer, 0.0 is returned.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1512
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1513
.SS Array
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1514
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1515
A JSON array is an ordered collection of other JSON values.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1516
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1517
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1518
.B json_t *json_array(void)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1519
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1520
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1521
Returns a new JSON array, or \fINULL\fP on error. Initially, the array
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1522
is empty.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1523
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1524
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1525
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1526
.B size_t json_array_size(const json_t\fI\ *array\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1527
Returns the number of elements in \fIarray\fP, or 0 if \fIarray\fP is NULL
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1528
or not a JSON array.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1529
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1530
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1531
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1532
.B json_t *json_array_get(const json_t\fI\ *array\fP, size_t\fI\ index\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1533
Return value: Borrowed reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1534
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1535
Returns the element in \fIarray\fP at position \fIindex\fP\&. The valid range
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1536
for \fIindex\fP is from 0 to the return value of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1537
\fBjson_array_size()\fP minus 1. If \fIarray\fP is not a JSON array,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1538
if \fIarray\fP is \fINULL\fP, or if \fIindex\fP is out of range, \fINULL\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1539
returned.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1540
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1541
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1542
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1543
.B int json_array_set(json_t\fI\ *array\fP, size_t\fI\ index\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1544
Replaces the element in \fIarray\fP at position \fIindex\fP with \fIvalue\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1545
The valid range for \fIindex\fP is from 0 to the return value of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1546
\fBjson_array_size()\fP minus 1. Returns 0 on success and \-1 on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1547
error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1548
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1549
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1550
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1551
.B int json_array_set_new(json_t\fI\ *array\fP, size_t\fI\ index\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1552
Like \fBjson_array_set()\fP but steals the reference to \fIvalue\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1553
This is useful when \fIvalue\fP is newly created and not used after
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1554
the call.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1555
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1556
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1557
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1558
.B int json_array_append(json_t\fI\ *array\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1559
Appends \fIvalue\fP to the end of \fIarray\fP, growing the size of \fIarray\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1560
by 1. Returns 0 on success and \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1561
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1562
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1563
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1564
.B int json_array_append_new(json_t\fI\ *array\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1565
Like \fBjson_array_append()\fP but steals the reference to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1566
\fIvalue\fP\&. This is useful when \fIvalue\fP is newly created and not used
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1567
after the call.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1568
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1569
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1570
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1571
.B int json_array_insert(json_t\fI\ *array\fP, size_t\fI\ index\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1572
Inserts \fIvalue\fP to \fIarray\fP at position \fIindex\fP, shifting the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1573
elements at \fIindex\fP and after it one position towards the end of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1574
the array. Returns 0 on success and \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1575
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1576
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1577
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1578
.B int json_array_insert_new(json_t\fI\ *array\fP, size_t\fI\ index\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1579
Like \fBjson_array_insert()\fP but steals the reference to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1580
\fIvalue\fP\&. This is useful when \fIvalue\fP is newly created and not used
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1581
after the call.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1582
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1583
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1584
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1585
.B int json_array_remove(json_t\fI\ *array\fP, size_t\fI\ index\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1586
Removes the element in \fIarray\fP at position \fIindex\fP, shifting the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1587
elements after \fIindex\fP one position towards the start of the array.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1588
Returns 0 on success and \-1 on error. The reference count of the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1589
removed value is decremented.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1590
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1591
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1592
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1593
.B int json_array_clear(json_t\fI\ *array\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1594
Removes all elements from \fIarray\fP\&. Returns 0 on sucess and \-1 on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1595
error. The reference count of all removed values are decremented.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1596
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1597
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1598
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1599
.B int json_array_extend(json_t\fI\ *array\fP, json_t\fI\ *other_array\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1600
Appends all elements in \fIother_array\fP to the end of \fIarray\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1601
Returns 0 on success and \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1602
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1603
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1604
The following macro can be used to iterate through all elements
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1605
in an array.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1606
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1607
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1608
.B json_array_foreach(array, index, value)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1609
Iterate over every element of \fBarray\fP, running the block
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1610
of code that follows each time with the proper values set to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1611
variables \fBindex\fP and \fBvalue\fP, of types \fBsize_t\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1612
\fBjson_t *\fP respectively. Example:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1613
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1614
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1615
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1616
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1617
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1618
/* array is a JSON array */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1619
size_t index;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1620
json_t *value;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1621
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1622
json_array_foreach(array, index, value) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1623
    /* block of code that uses index and value */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1624
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1625
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1626
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1627
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1628
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1629
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1630
The items are returned in increasing index order.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1631
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1632
This macro expands to an ordinary \fBfor\fP statement upon
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1633
preprocessing, so its performance is equivalent to that of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1634
hand\-written code using the array access functions.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1635
The main advantage of this macro is that it abstracts
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1636
away the complexity, and makes for shorter, more
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1637
concise code.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1638
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1639
New in version 2.5.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1640
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1641
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1642
.SS Object
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1643
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1644
A JSON object is a dictionary of key\-value pairs, where the key is a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1645
Unicode string and the value is any JSON value.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1646
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1647
Even though NUL bytes are allowed in string values, they are not
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1648
allowed in object keys.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1649
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1650
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1651
.B json_t *json_object(void)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1652
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1653
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1654
Returns a new JSON object, or \fINULL\fP on error. Initially, the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1655
object is empty.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1656
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1657
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1658
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1659
.B size_t json_object_size(const json_t\fI\ *object\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1660
Returns the number of elements in \fIobject\fP, or 0 if \fIobject\fP is not
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1661
a JSON object.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1662
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1663
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1664
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1665
.B json_t *json_object_get(const json_t\fI\ *object\fP, const char\fI\ *key\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1666
Return value: Borrowed reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1667
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1668
Get a value corresponding to \fIkey\fP from \fIobject\fP\&. Returns \fINULL\fP if
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1669
\fIkey\fP is not found and on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1670
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1671
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1672
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1673
.B int json_object_set(json_t\fI\ *object\fP, const char\fI\ *key\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1674
Set the value of \fIkey\fP to \fIvalue\fP in \fIobject\fP\&. \fIkey\fP must be a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1675
valid null terminated UTF\-8 encoded Unicode string. If there
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1676
already is a value for \fIkey\fP, it is replaced by the new value.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1677
Returns 0 on success and \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1678
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1679
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1680
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1681
.B int json_object_set_nocheck(json_t\fI\ *object\fP, const char\fI\ *key\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1682
Like \fBjson_object_set()\fP, but doesn\(aqt check that \fIkey\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1683
valid UTF\-8. Use this function only if you are certain that this
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1684
really is the case (e.g. you have already checked it by other
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1685
means).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1686
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1687
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1688
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1689
.B int json_object_set_new(json_t\fI\ *object\fP, const char\fI\ *key\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1690
Like \fBjson_object_set()\fP but steals the reference to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1691
\fIvalue\fP\&. This is useful when \fIvalue\fP is newly created and not used
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1692
after the call.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1693
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1694
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1695
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1696
.B int json_object_set_new_nocheck(json_t\fI\ *object\fP, const char\fI\ *key\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1697
Like \fBjson_object_set_new()\fP, but doesn\(aqt check that \fIkey\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1698
valid UTF\-8. Use this function only if you are certain that this
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1699
really is the case (e.g. you have already checked it by other
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1700
means).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1701
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1702
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1703
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1704
.B int json_object_del(json_t\fI\ *object\fP, const char\fI\ *key\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1705
Delete \fIkey\fP from \fIobject\fP if it exists. Returns 0 on success, or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1706
\-1 if \fIkey\fP was not found. The reference count of the removed value
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1707
is decremented.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1708
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1709
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1710
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1711
.B int json_object_clear(json_t\fI\ *object\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1712
Remove all elements from \fIobject\fP\&. Returns 0 on success and \-1 if
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1713
\fIobject\fP is not a JSON object. The reference count of all removed
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1714
values are decremented.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1715
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1716
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1717
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1718
.B int json_object_update(json_t\fI\ *object\fP, json_t\fI\ *other\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1719
Update \fIobject\fP with the key\-value pairs from \fIother\fP, overwriting
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1720
existing keys. Returns 0 on success or \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1721
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1722
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1723
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1724
.B int json_object_update_existing(json_t\fI\ *object\fP, json_t\fI\ *other\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1725
Like \fBjson_object_update()\fP, but only the values of existing
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1726
keys are updated. No new keys are created. Returns 0 on success or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1727
\-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1728
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1729
New in version 2.3.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1730
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1731
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1732
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1733
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1734
.B int json_object_update_missing(json_t\fI\ *object\fP, json_t\fI\ *other\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1735
Like \fBjson_object_update()\fP, but only new keys are created.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1736
The value of any existing key is not changed. Returns 0 on success
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1737
or \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1738
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1739
New in version 2.3.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1740
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1741
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1742
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1743
The following macro can be used to iterate through all key\-value pairs
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1744
in an object.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1745
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1746
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1747
.B json_object_foreach(object, key, value)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1748
Iterate over every key\-value pair of \fBobject\fP, running the block
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1749
of code that follows each time with the proper values set to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1750
variables \fBkey\fP and \fBvalue\fP, of types \fBconst char *\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1751
\fBjson_t *\fP respectively. Example:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1752
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1753
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1754
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1755
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1756
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1757
/* obj is a JSON object */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1758
const char *key;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1759
json_t *value;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1760
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1761
json_object_foreach(obj, key, value) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1762
    /* block of code that uses key and value */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1763
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1764
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1765
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1766
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1767
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1768
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1769
The items are not returned in any particular order.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1770
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1771
This macro expands to an ordinary \fBfor\fP statement upon
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1772
preprocessing, so its performance is equivalent to that of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1773
hand\-written iteration code using the object iteration protocol
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1774
(see below). The main advantage of this macro is that it abstracts
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1775
away the complexity behind iteration, and makes for shorter, more
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1776
concise code.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1777
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1778
New in version 2.3.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1779
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1780
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1781
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1782
The following functions implement an iteration protocol for objects,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1783
allowing to iterate through all key\-value pairs in an object. The
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1784
items are not returned in any particular order, as this would require
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1785
sorting due to the internal hashtable implementation.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1786
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1787
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1788
.B void *json_object_iter(json_t\fI\ *object\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1789
Returns an opaque iterator which can be used to iterate over all
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1790
key\-value pairs in \fIobject\fP, or \fINULL\fP if \fIobject\fP is empty.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1791
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1792
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1793
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1794
.B void *json_object_iter_at(json_t\fI\ *object\fP, const char\fI\ *key\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1795
Like \fBjson_object_iter()\fP, but returns an iterator to the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1796
key\-value pair in \fIobject\fP whose key is equal to \fIkey\fP, or NULL if
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1797
\fIkey\fP is not found in \fIobject\fP\&. Iterating forward to the end of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1798
\fIobject\fP only yields all key\-value pairs of the object if \fIkey\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1799
happens to be the first key in the underlying hash table.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1800
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1801
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1802
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1803
.B void *json_object_iter_next(json_t\fI\ *object\fP, void\fI\ *iter\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1804
Returns an iterator pointing to the next key\-value pair in \fIobject\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1805
after \fIiter\fP, or \fINULL\fP if the whole object has been iterated
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1806
through.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1807
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1808
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1809
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1810
.B const char *json_object_iter_key(void\fI\ *iter\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1811
Extract the associated key from \fIiter\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1812
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1813
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1814
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1815
.B json_t *json_object_iter_value(void\fI\ *iter\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1816
Return value: Borrowed reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1817
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1818
Extract the associated value from \fIiter\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1819
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1820
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1821
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1822
.B int json_object_iter_set(json_t\fI\ *object\fP, void\fI\ *iter\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1823
Set the value of the key\-value pair in \fIobject\fP, that is pointed to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1824
by \fIiter\fP, to \fIvalue\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1825
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1826
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1827
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1828
.B int json_object_iter_set_new(json_t\fI\ *object\fP, void\fI\ *iter\fP, json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1829
Like \fBjson_object_iter_set()\fP, but steals the reference to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1830
\fIvalue\fP\&. This is useful when \fIvalue\fP is newly created and not used
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1831
after the call.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1832
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1833
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1834
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1835
.B void *json_object_key_to_iter(const char\fI\ *key\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1836
Like \fBjson_object_iter_at()\fP, but much faster. Only works for
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1837
values returned by \fBjson_object_iter_key()\fP\&. Using other keys
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1838
will lead to segfaults. This function is used internally to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1839
implement \fBjson_object_foreach()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1840
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1841
New in version 2.3.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1842
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1843
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1844
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1845
The iteration protocol can be used for example as follows:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1846
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1847
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1848
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1849
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1850
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1851
/* obj is a JSON object */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1852
const char *key;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1853
json_t *value;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1854
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1855
void *iter = json_object_iter(obj);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1856
while(iter)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1857
{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1858
    key = json_object_iter_key(iter);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1859
    value = json_object_iter_value(iter);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1860
    /* use key and value ... */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1861
    iter = json_object_iter_next(obj, iter);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1862
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1863
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1864
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1865
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1866
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1867
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1868
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1869
.B void json_object_seed(size_t\fI\ seed\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1870
Seed the hash function used in Jansson\(aqs hashtable implementation.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1871
The seed is used to randomize the hash function so that an
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1872
attacker cannot control its output.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1873
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1874
If \fIseed\fP is 0, Jansson generates the seed itselfy by reading
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1875
random data from the operating system\(aqs entropy sources. If no
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1876
entropy sources are available, falls back to using a combination
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1877
of the current timestamp (with microsecond precision if possible)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1878
and the process ID.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1879
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1880
If called at all, this function must be called before any calls to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1881
\fBjson_object()\fP, either explicit or implicit. If this
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1882
function is not called by the user, the first call to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1883
\fBjson_object()\fP (either explicit or implicit) seeds the hash
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1884
function. See \fIportability\-thread\-safety\fP for notes on thread
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1885
safety.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1886
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1887
If repeatable results are required, for e.g. unit tests, the hash
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1888
function can be "unrandomized" by calling \fBjson_object_seed()\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1889
with a constant value on program startup, e.g.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1890
\fBjson_object_seed(1)\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1891
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1892
New in version 2.6.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1893
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1894
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1895
.SS Error reporting
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1896
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1897
Jansson uses a single struct type to pass error information to the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1898
user. See sections \fIapiref\-decoding\fP, \fIapiref\-pack\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1899
\fIapiref\-unpack\fP for functions that pass error information using
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1900
this struct.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1901
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1902
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1903
.B json_error_t
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1904
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1905
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1906
.B char text[]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1907
The error message (in UTF\-8), or an empty string if a message is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1908
not available.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1909
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1910
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1911
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1912
.B char source[]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1913
Source of the error. This can be (a part of) the file name or a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1914
special identifier in angle brackers (e.g. \fB<string>\fP).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1915
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1916
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1917
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1918
.B int line
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1919
The line number on which the error occurred.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1920
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1921
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1922
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1923
.B int column
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1924
The column on which the error occurred. Note that this is the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1925
\fIcharacter column\fP, not the byte column, i.e. a multibyte UTF\-8
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1926
character counts as one column.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1927
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1928
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1929
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1930
.B size_t position
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1931
The position in bytes from the start of the input. This is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1932
useful for debugging Unicode encoding problems.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1933
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1934
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1935
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1936
The normal use of \fBjson_error_t\fP is to allocate it on the stack,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1937
and pass a pointer to a function. Example:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1938
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1939
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1940
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1941
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1942
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1943
int main() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1944
    json_t *json;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1945
    json_error_t error;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1946
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1947
    json = json_load_file("/path/to/file.json", 0, &error);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1948
    if(!json) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1949
        /* the error variable contains error information */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1950
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1951
    ...
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1952
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1953
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1954
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1955
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1956
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1957
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1958
Also note that if the call succeeded (\fBjson != NULL\fP in the above
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1959
example), the contents of \fBerror\fP are generally left unspecified.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1960
The decoding functions write to the \fBposition\fP member also on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1961
success. See \fIapiref\-decoding\fP for more info.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1962
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1963
All functions also accept \fINULL\fP as the \fBjson_error_t\fP pointer,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1964
in which case no error information is returned to the caller.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1965
.SS Encoding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1966
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1967
This sections describes the functions that can be used to encode
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1968
values to JSON. By default, only objects and arrays can be encoded
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1969
directly, since they are the only valid \fIroot\fP values of a JSON text.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1970
To encode any JSON value, use the \fBJSON_ENCODE_ANY\fP flag (see
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1971
below).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1972
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1973
By default, the output has no newlines, and spaces are used between
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1974
array and object elements for a readable output. This behavior can be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1975
altered by using the \fBJSON_INDENT\fP and \fBJSON_COMPACT\fP flags
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1976
described below. A newline is never appended to the end of the encoded
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1977
JSON data.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1978
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1979
Each function takes a \fIflags\fP parameter that controls some aspects of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1980
how the data is encoded. Its default value is 0. The following macros
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1981
can be ORed together to obtain \fIflags\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1982
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1983
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1984
.B \fBJSON_INDENT(n)\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1985
Pretty\-print the result, using newlines between array and object
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1986
items, and indenting with \fIn\fP spaces. The valid range for \fIn\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1987
between 0 and 31 (inclusive), other values result in an undefined
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1988
output. If \fBJSON_INDENT\fP is not used or \fIn\fP is 0, no newlines are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1989
inserted between array and object items.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1990
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1991
The \fBJSON_MAX_INDENT\fP constant defines the maximum indentation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1992
that can be used, and its value is 31.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1993
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1994
Changed in version 2.7: Added \fBJSON_MAX_INDENT\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1995
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1996
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1997
.B \fBJSON_COMPACT\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1998
This flag enables a compact representation, i.e. sets the separator
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  1999
between array and object items to \fB","\fP and between object keys
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2000
and values to \fB":"\fP\&. Without this flag, the corresponding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2001
separators are \fB", "\fP and \fB": "\fP for more readable output.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2002
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2003
.B \fBJSON_ENSURE_ASCII\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2004
If this flag is used, the output is guaranteed to consist only of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2005
ASCII characters. This is achived by escaping all Unicode
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2006
characters outside the ASCII range.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2007
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2008
.B \fBJSON_SORT_KEYS\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2009
If this flag is used, all the objects in output are sorted by key.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2010
This is useful e.g. if two JSON texts are diffed or visually
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2011
compared.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2012
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2013
.B \fBJSON_PRESERVE_ORDER\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2014
If this flag is used, object keys in the output are sorted into the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2015
same order in which they were first inserted to the object. For
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2016
example, decoding a JSON text and then encoding with this flag
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2017
preserves the order of object keys.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2018
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2019
.B \fBJSON_ENCODE_ANY\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2020
Specifying this flag makes it possible to encode any JSON value on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2021
its own. Without it, only objects and arrays can be passed as the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2022
\fIroot\fP value to the encoding functions.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2023
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2024
\fBNote:\fP Encoding any value may be useful in some scenarios, but
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2025
it\(aqs generally discouraged as it violates strict compatiblity with
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2026
\fI\%RFC 4627\fP\&. If you use this flag, don\(aqt expect interoperatibility
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2027
with other JSON systems.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2028
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2029
New in version 2.1.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2030
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2031
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2032
.B \fBJSON_ESCAPE_SLASH\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2033
Escape the \fB/\fP characters in strings with \fB\e/\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2034
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2035
New in version 2.4.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2036
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2037
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2038
.B \fBJSON_REAL_PRECISION(n)\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2039
Output all real numbers with at most \fIn\fP digits of precision. The
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2040
valid range for \fIn\fP is between 0 and 31 (inclusive), and other
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2041
values result in an undefined behavior.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2042
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2043
By default, the precision is 17, to correctly and losslessly encode
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2044
all IEEE 754 double precision floating point numbers.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2045
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2046
New in version 2.7.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2047
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2048
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2049
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2050
The following functions perform the actual JSON encoding. The result
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2051
is in UTF\-8.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2052
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2053
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2054
.B char *json_dumps(const json_t\fI\ *root\fP, size_t\fI\ flags\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2055
Returns the JSON representation of \fIroot\fP as a string, or \fINULL\fP on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2056
error. \fIflags\fP is described above. The return value must be freed
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2057
by the caller using \fBfree()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2058
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2059
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2060
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2061
.B int json_dumpf(const json_t\fI\ *root\fP, FILE\fI\ *output\fP, size_t\fI\ flags\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2062
Write the JSON representation of \fIroot\fP to the stream \fIoutput\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2063
\fIflags\fP is described above. Returns 0 on success and \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2064
If an error occurs, something may have already been written to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2065
\fIoutput\fP\&. In this case, the output is undefined and most likely not
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2066
valid JSON.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2067
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2068
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2069
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2070
.B int json_dump_file(const json_t\fI\ *json\fP, const char\fI\ *path\fP, size_t\fI\ flags\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2071
Write the JSON representation of \fIroot\fP to the file \fIpath\fP\&. If
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2072
\fIpath\fP already exists, it is overwritten. \fIflags\fP is described
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2073
above. Returns 0 on success and \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2074
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2075
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2076
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2077
.B json_dump_callback_t
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2078
A typedef for a function that\(aqs called by
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2079
\fBjson_dump_callback()\fP:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2080
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2081
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2082
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2083
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2084
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2085
typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2086
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2087
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2088
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2089
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2090
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2091
\fIbuffer\fP points to a buffer containing a chunk of output, \fIsize\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2092
the length of the buffer, and \fIdata\fP is the corresponding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2093
\fBjson_dump_callback()\fP argument passed through.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2094
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2095
On error, the function should return \-1 to stop the encoding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2096
process. On success, it should return 0.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2097
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2098
New in version 2.2.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2099
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2100
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2101
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2102
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2103
.B int json_dump_callback(const json_t\fI\ *json\fP, json_dump_callback_t\fI\ callback\fP, void\fI\ *data\fP, size_t\fI\ flags\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2104
Call \fIcallback\fP repeatedly, passing a chunk of the JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2105
representation of \fIroot\fP each time. \fIflags\fP is described above.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2106
Returns 0 on success and \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2107
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2108
New in version 2.2.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2109
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2110
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2111
.SS Decoding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2112
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2113
This sections describes the functions that can be used to decode JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2114
text to the Jansson representation of JSON data. The JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2115
specification requires that a JSON text is either a serialized array
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2116
or object, and this requirement is also enforced with the following
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2117
functions. In other words, the top level value in the JSON text being
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2118
decoded must be either array or object. To decode any JSON value, use
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2119
the \fBJSON_DECODE_ANY\fP flag (see below).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2120
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2121
See \fIrfc\-conformance\fP for a discussion on Jansson\(aqs conformance
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2122
to the JSON specification. It explains many design decisions that
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2123
affect especially the behavior of the decoder.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2124
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2125
Each function takes a \fIflags\fP parameter that can be used to control
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2126
the behavior of the decoder. Its default value is 0. The following
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2127
macros can be ORed together to obtain \fIflags\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2128
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2129
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2130
.B \fBJSON_REJECT_DUPLICATES\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2131
Issue a decoding error if any JSON object in the input text
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2132
contains duplicate keys. Without this flag, the value of the last
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2133
occurence of each key ends up in the result. Key equivalence is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2134
checked byte\-by\-byte, without special Unicode comparison
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2135
algorithms.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2136
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2137
New in version 2.1.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2138
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2139
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2140
.B \fBJSON_DECODE_ANY\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2141
By default, the decoder expects an array or object as the input.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2142
With this flag enabled, the decoder accepts any valid JSON value.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2143
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2144
\fBNote:\fP Decoding any value may be useful in some scenarios, but
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2145
it\(aqs generally discouraged as it violates strict compatiblity with
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2146
\fI\%RFC 4627\fP\&. If you use this flag, don\(aqt expect interoperatibility
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2147
with other JSON systems.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2148
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2149
New in version 2.3.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2150
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2151
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2152
.B \fBJSON_DISABLE_EOF_CHECK\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2153
By default, the decoder expects that its whole input constitutes a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2154
valid JSON text, and issues an error if there\(aqs extra data after
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2155
the otherwise valid JSON input. With this flag enabled, the decoder
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2156
stops after decoding a valid JSON array or object, and thus allows
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2157
extra data after the JSON text.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2158
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2159
Normally, reading will stop when the last \fB]\fP or \fB}\fP in the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2160
JSON input is encountered. If both \fBJSON_DISABLE_EOF_CHECK\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2161
\fBJSON_DECODE_ANY\fP flags are used, the decoder may read one extra
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2162
UTF\-8 code unit (up to 4 bytes of input). For example, decoding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2163
\fB4true\fP correctly decodes the integer 4, but also reads the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2164
\fBt\fP\&. For this reason, if reading multiple consecutive values that
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2165
are not arrays or objects, they should be separated by at least one
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2166
whitespace character.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2167
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2168
New in version 2.1.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2169
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2170
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2171
.B \fBJSON_DECODE_INT_AS_REAL\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2172
JSON defines only one number type. Jansson distinguishes between
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2173
ints and reals. For more information see \fIreal\-vs\-integer\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2174
With this flag enabled the decoder interprets all numbers as real
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2175
values. Integers that do not have an exact double representation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2176
will silently result in a loss of precision. Integers that cause
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2177
a double overflow will cause an error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2178
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2179
New in version 2.5.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2180
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2181
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2182
.B \fBJSON_ALLOW_NUL\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2183
Allow \fB\eu0000\fP escape inside string values. This is a safety
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2184
measure; If you know your input can contain NUL bytes, use this
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2185
flag. If you don\(aqt use this flag, you don\(aqt have to worry about NUL
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2186
bytes inside strings unless you explicitly create themselves by
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2187
using e.g. \fBjson_stringn()\fP or \fBs#\fP format specifier for
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2188
\fBjson_pack()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2189
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2190
Object keys cannot have embedded NUL bytes even if this flag is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2191
used.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2192
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2193
New in version 2.6.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2194
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2195
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2196
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2197
Each function also takes an optional \fBjson_error_t\fP parameter
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2198
that is filled with error information if decoding fails. It\(aqs also
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2199
updated on success; the number of bytes of input read is written to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2200
its \fBposition\fP field. This is especially useful when using
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2201
\fBJSON_DISABLE_EOF_CHECK\fP to read multiple consecutive JSON texts.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2202
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2203
New in version 2.3: Number of bytes of input read is written to the \fBposition\fP field
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2204
of the \fBjson_error_t\fP structure.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2205
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2206
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2207
If no error or position information is needed, you can pass \fINULL\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2208
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2209
The following functions perform the actual JSON decoding.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2210
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2211
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2212
.B json_t *json_loads(const char\fI\ *input\fP, size_t\fI\ flags\fP, json_error_t\fI\ *error\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2213
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2214
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2215
Decodes the JSON string \fIinput\fP and returns the array or object it
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2216
contains, or \fINULL\fP on error, in which case \fIerror\fP is filled with
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2217
information about the error. \fIflags\fP is described above.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2218
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2219
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2220
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2221
.B json_t *json_loadb(const char\fI\ *buffer\fP, size_t\fI\ buflen\fP, size_t\fI\ flags\fP, json_error_t\fI\ *error\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2222
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2223
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2224
Decodes the JSON string \fIbuffer\fP, whose length is \fIbuflen\fP, and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2225
returns the array or object it contains, or \fINULL\fP on error, in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2226
which case \fIerror\fP is filled with information about the error. This
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2227
is similar to \fBjson_loads()\fP except that the string doesn\(aqt
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2228
need to be null\-terminated. \fIflags\fP is described above.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2229
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2230
New in version 2.1.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2231
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2232
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2233
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2234
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2235
.B json_t *json_loadf(FILE\fI\ *input\fP, size_t\fI\ flags\fP, json_error_t\fI\ *error\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2236
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2237
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2238
Decodes the JSON text in stream \fIinput\fP and returns the array or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2239
object it contains, or \fINULL\fP on error, in which case \fIerror\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2240
filled with information about the error. \fIflags\fP is described
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2241
above.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2242
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2243
This function will start reading the input from whatever position
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2244
the input file was, without attempting to seek first. If an error
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2245
occurs, the file position will be left indeterminate. On success,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2246
the file position will be at EOF, unless \fBJSON_DISABLE_EOF_CHECK\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2247
flag was used. In this case, the file position will be at the first
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2248
character after the last \fB]\fP or \fB}\fP in the JSON input. This
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2249
allows calling \fBjson_loadf()\fP on the same \fBFILE\fP object
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2250
multiple times, if the input consists of consecutive JSON texts,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2251
possibly separated by whitespace.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2252
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2253
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2254
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2255
.B json_t *json_load_file(const char\fI\ *path\fP, size_t\fI\ flags\fP, json_error_t\fI\ *error\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2256
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2257
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2258
Decodes the JSON text in file \fIpath\fP and returns the array or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2259
object it contains, or \fINULL\fP on error, in which case \fIerror\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2260
filled with information about the error. \fIflags\fP is described
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2261
above.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2262
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2263
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2264
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2265
.B json_load_callback_t
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2266
A typedef for a function that\(aqs called by
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2267
\fBjson_load_callback()\fP to read a chunk of input data:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2268
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2269
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2270
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2271
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2272
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2273
typedef size_t (*json_load_callback_t)(void *buffer, size_t buflen, void *data);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2274
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2275
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2276
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2277
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2278
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2279
\fIbuffer\fP points to a buffer of \fIbuflen\fP bytes, and \fIdata\fP is the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2280
corresponding \fBjson_load_callback()\fP argument passed through.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2281
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2282
On success, the function should return the number of bytes read; a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2283
returned value of 0 indicates that no data was read and that the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2284
end of file has been reached. On error, the function should return
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2285
\fB(size_t)\-1\fP to abort the decoding process.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2286
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2287
New in version 2.4.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2288
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2289
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2290
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2291
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2292
.B json_t *json_load_callback(json_load_callback_t\fI\ callback\fP, void\fI\ *data\fP, size_t\fI\ flags\fP, json_error_t\fI\ *error\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2293
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2294
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2295
Decodes the JSON text produced by repeated calls to \fIcallback\fP, and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2296
returns the array or object it contains, or \fINULL\fP on error, in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2297
which case \fIerror\fP is filled with information about the error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2298
\fIdata\fP is passed through to \fIcallback\fP on each call. \fIflags\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2299
described above.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2300
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2301
New in version 2.4.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2302
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2303
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2304
.SS Building Values
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2305
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2306
This section describes functions that help to create, or \fIpack\fP,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2307
complex JSON values, especially nested objects and arrays. Value
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2308
building is based on a \fIformat string\fP that is used to tell the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2309
functions about the expected arguments.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2310
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2311
For example, the format string \fB"i"\fP specifies a single integer
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2312
value, while the format string \fB"[ssb]"\fP or the equivalent \fB"[s, s,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2313
b]"\fP specifies an array value with two strings and a boolean as its
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2314
items:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2315
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2316
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2317
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2318
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2319
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2320
/* Create the JSON integer 42 */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2321
json_pack("i", 42);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2322
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2323
/* Create the JSON array ["foo", "bar", true] */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2324
json_pack("[ssb]", "foo", "bar", 1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2325
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2326
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2327
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2328
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2329
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2330
Here\(aqs the full list of format specifiers. The type in parentheses
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2331
denotes the resulting JSON type, and the type in brackets (if any)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2332
denotes the C type that is expected as the corresponding argument or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2333
arguments.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2334
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2335
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2336
.B \fBs\fP (string) [const char *]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2337
Convert a NULL terminated UTF\-8 string to a JSON string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2338
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2339
.B \fBs#\fP (string) [const char *, int]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2340
Convert a UTF\-8 buffer of a given length to a JSON string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2341
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2342
New in version 2.5.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2343
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2344
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2345
.B \fBs%\fP (string) [const char *, size_t]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2346
Like \fBs#\fP but the length argument is of type \fBsize_t\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2347
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2348
New in version 2.6.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2349
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2350
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2351
.B \fB+\fP [const char *]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2352
Like \fBs\fP, but concatenate to the previous string. Only valid
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2353
after \fBs\fP, \fBs#\fP, \fB+\fP or \fB+#\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2354
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2355
New in version 2.5.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2356
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2357
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2358
.B \fB+#\fP [const char *, int]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2359
Like \fBs#\fP, but concatenate to the previous string. Only valid
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2360
after \fBs\fP, \fBs#\fP, \fB+\fP or \fB+#\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2361
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2362
New in version 2.5.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2363
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2364
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2365
.B \fB+%\fP (string) [const char *, size_t]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2366
Like \fB+#\fP but the length argument is of type \fBsize_t\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2367
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2368
New in version 2.6.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2369
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2370
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2371
.B \fBn\fP (null)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2372
Output a JSON null value. No argument is consumed.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2373
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2374
.B \fBb\fP (boolean) [int]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2375
Convert a C \fBint\fP to JSON boolean value. Zero is converted
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2376
to \fBfalse\fP and non\-zero to \fBtrue\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2377
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2378
.B \fBi\fP (integer) [int]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2379
Convert a C \fBint\fP to JSON integer.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2380
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2381
.B \fBI\fP (integer) [json_int_t]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2382
Convert a C \fBjson_int_t\fP to JSON integer.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2383
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2384
.B \fBf\fP (real) [double]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2385
Convert a C \fBdouble\fP to JSON real.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2386
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2387
.B \fBo\fP (any value) [json_t *]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2388
Output any given JSON value as\-is. If the value is added to an
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2389
array or object, the reference to the value passed to \fBo\fP is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2390
stolen by the container.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2391
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2392
.B \fBO\fP (any value) [json_t *]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2393
Like \fBo\fP, but the argument\(aqs reference count is incremented.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2394
This is useful if you pack into an array or object and want to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2395
keep the reference for the JSON value consumed by \fBO\fP to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2396
yourself.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2397
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2398
.B \fB[fmt]\fP (array)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2399
Build an array with contents from the inner format string. \fBfmt\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2400
may contain objects and arrays, i.e. recursive value building is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2401
supported.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2402
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2403
.B \fB{fmt}\fP (object)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2404
Build an object with contents from the inner format string
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2405
\fBfmt\fP\&. The first, third, etc. format specifier represent a key,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2406
and must be a string (see \fBs\fP, \fBs#\fP, \fB+\fP and \fB+#\fP above),
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2407
as object keys are always strings. The second, fourth, etc. format
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2408
specifier represent a value. Any value may be an object or array,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2409
i.e. recursive value building is supported.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2410
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2411
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2412
Whitespace, \fB:\fP and \fB,\fP are ignored.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2413
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2414
The following functions compose the value building API:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2415
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2416
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2417
.B json_t *json_pack(const char\fI\ *fmt\fP, \&...)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2418
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2419
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2420
Build a new JSON value according to the format string \fIfmt\fP\&. For
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2421
each format specifier (except for \fB{}[]n\fP), one or more arguments
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2422
are consumed and used to build the corresponding value. Returns
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2423
\fINULL\fP on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2424
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2425
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2426
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2427
.B json_t *json_pack_ex(json_error_t\fI\ *error\fP, size_t\fI\ flags\fP, const char\fI\ *fmt\fP, \&...)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2428
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2429
.B json_t *json_vpack_ex(json_error_t\fI\ *error\fP, size_t\fI\ flags\fP, const char\fI\ *fmt\fP, va_list\fI\ ap\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2430
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2431
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2432
Like \fBjson_pack()\fP, but an in the case of an error, an error
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2433
message is written to \fIerror\fP, if it\(aqs not \fINULL\fP\&. The \fIflags\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2434
parameter is currently unused and should be set to 0.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2435
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2436
As only the errors in format string (and out\-of\-memory errors) can
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2437
be caught by the packer, these two functions are most likely only
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2438
useful for debugging format strings.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2439
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2440
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2441
More examples:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2442
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2443
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2444
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2445
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2446
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2447
/* Build an empty JSON object */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2448
json_pack("{}");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2449
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2450
/* Build the JSON object {"foo": 42, "bar": 7} */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2451
json_pack("{sisi}", "foo", 42, "bar", 7);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2452
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2453
/* Like above, \(aq:\(aq, \(aq,\(aq and whitespace are ignored */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2454
json_pack("{s:i, s:i}", "foo", 42, "bar", 7);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2455
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2456
/* Build the JSON array [[1, 2], {"cool": true}] */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2457
json_pack("[[i,i],{s:b}]", 1, 2, "cool", 1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2458
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2459
/* Build a string from a non\-NUL terminated buffer */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2460
char buffer[4] = {\(aqt\(aq, \(aqe\(aq, \(aqs\(aq, \(aqt\(aq};
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2461
json_pack("s#", buffer, 4);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2462
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2463
/* Concatentate strings together to build the JSON string "foobarbaz" */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2464
json_pack("s++", "foo", "bar", "baz");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2465
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2466
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2467
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2468
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2469
.SS Parsing and Validating Values
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2470
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2471
This section describes functions that help to validate complex values
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2472
and extract, or \fIunpack\fP, data from them. Like \fIbuilding values\fP, this is also based on format strings.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2473
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2474
While a JSON value is unpacked, the type specified in the format
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2475
string is checked to match that of the JSON value. This is the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2476
validation part of the process. In addition to this, the unpacking
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2477
functions can also check that all items of arrays and objects are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2478
unpacked. This check be enabled with the format specifier \fB!\fP or by
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2479
using the flag \fBJSON_STRICT\fP\&. See below for details.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2480
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2481
Here\(aqs the full list of format specifiers. The type in parentheses
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2482
denotes the JSON type, and the type in brackets (if any) denotes the C
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2483
type whose address should be passed.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2484
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2485
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2486
.B \fBs\fP (string) [const char *]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2487
Convert a JSON string to a pointer to a NULL terminated UTF\-8
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2488
string. The resulting string is extracted by using
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2489
\fBjson_string_value()\fP internally, so it exists as long as
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2490
there are still references to the corresponding JSON string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2491
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2492
.B \fBs%\fP (string) [const char *, size_t *]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2493
Convert a JSON string to a pointer to a NULL terminated UTF\-8
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2494
string and its length.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2495
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2496
New in version 2.6.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2497
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2498
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2499
.B \fBn\fP (null)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2500
Expect a JSON null value. Nothing is extracted.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2501
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2502
.B \fBb\fP (boolean) [int]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2503
Convert a JSON boolean value to a C \fBint\fP, so that \fBtrue\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2504
is converted to 1 and \fBfalse\fP to 0.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2505
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2506
.B \fBi\fP (integer) [int]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2507
Convert a JSON integer to C \fBint\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2508
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2509
.B \fBI\fP (integer) [json_int_t]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2510
Convert a JSON integer to C \fBjson_int_t\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2511
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2512
.B \fBf\fP (real) [double]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2513
Convert a JSON real to C \fBdouble\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2514
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2515
.B \fBF\fP (integer or real) [double]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2516
Convert a JSON number (integer or real) to C \fBdouble\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2517
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2518
.B \fBo\fP (any value) [json_t *]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2519
Store a JSON value with no conversion to a \fBjson_t\fP pointer.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2520
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2521
.B \fBO\fP (any value) [json_t *]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2522
Like \fBO\fP, but the JSON value\(aqs reference count is incremented.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2523
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2524
.B \fB[fmt]\fP (array)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2525
Convert each item in the JSON array according to the inner format
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2526
string. \fBfmt\fP may contain objects and arrays, i.e. recursive
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2527
value extraction is supporetd.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2528
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2529
.B \fB{fmt}\fP (object)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2530
Convert each item in the JSON object according to the inner format
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2531
string \fBfmt\fP\&. The first, third, etc. format specifier represent
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2532
a key, and must be \fBs\fP\&. The corresponding argument to unpack
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2533
functions is read as the object key. The second fourth, etc.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2534
format specifier represent a value and is written to the address
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2535
given as the corresponding argument. \fBNote\fP that every other
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2536
argument is read from and every other is written to.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2537
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2538
\fBfmt\fP may contain objects and arrays as values, i.e. recursive
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2539
value extraction is supporetd.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2540
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2541
New in version 2.3: Any \fBs\fP representing a key may be suffixed with a \fB?\fP to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2542
make the key optional. If the key is not found, nothing is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2543
extracted. See below for an example.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2544
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2545
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2546
.B \fB!\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2547
This special format specifier is used to enable the check that
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2548
all object and array items are accessed, on a per\-value basis. It
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2549
must appear inside an array or object as the last format specifier
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2550
before the closing bracket or brace. To enable the check globally,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2551
use the \fBJSON_STRICT\fP unpacking flag.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2552
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2553
.B \fB*\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2554
This special format specifier is the opposite of \fB!\fP\&. If the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2555
\fBJSON_STRICT\fP flag is used, \fB*\fP can be used to disable the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2556
strict check on a per\-value basis. It must appear inside an array
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2557
or object as the last format specifier before the closing bracket
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2558
or brace.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2559
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2560
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2561
Whitespace, \fB:\fP and \fB,\fP are ignored.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2562
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2563
The following functions compose the parsing and validation API:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2564
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2565
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2566
.B int json_unpack(json_t\fI\ *root\fP, const char\fI\ *fmt\fP, \&...)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2567
Validate and unpack the JSON value \fIroot\fP according to the format
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2568
string \fIfmt\fP\&. Returns 0 on success and \-1 on failure.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2569
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2570
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2571
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2572
.B int json_unpack_ex(json_t\fI\ *root\fP, json_error_t\fI\ *error\fP, size_t\fI\ flags\fP, const char\fI\ *fmt\fP, \&...)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2573
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2574
.B int json_vunpack_ex(json_t\fI\ *root\fP, json_error_t\fI\ *error\fP, size_t\fI\ flags\fP, const char\fI\ *fmt\fP, va_list\fI\ ap\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2575
Validate and unpack the JSON value \fIroot\fP according to the format
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2576
string \fIfmt\fP\&. If an error occurs and \fIerror\fP is not \fINULL\fP, write
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2577
error information to \fIerror\fP\&. \fIflags\fP can be used to control the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2578
behaviour of the unpacker, see below for the flags. Returns 0 on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2579
success and \-1 on failure.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2580
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2581
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2582
\fBNOTE:\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2583
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2584
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2585
The first argument of all unpack functions is \fBjson_t *root\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2586
instead of \fBconst json_t *root\fP, because the use of \fBO\fP format
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2587
specifier causes the reference count of \fBroot\fP, or some value
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2588
reachable from \fBroot\fP, to be increased. Furthermore, the \fBo\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2589
format specifier may be used to extract a value as\-is, which allows
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2590
modifying the structure or contents of a value reachable from
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2591
\fBroot\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2592
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2593
If the \fBO\fP and \fBo\fP format specifiers are not used, it\(aqs
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2594
perfectly safe to cast a \fBconst json_t *\fP variable to plain
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2595
\fBjson_t *\fP when used with these functions.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2596
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2597
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2598
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2599
The following unpacking flags are available:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2600
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2601
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2602
.B \fBJSON_STRICT\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2603
Enable the extra validation step checking that all object and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2604
array items are unpacked. This is equivalent to appending the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2605
format specifier \fB!\fP to the end of every array and object in the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2606
format string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2607
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2608
.B \fBJSON_VALIDATE_ONLY\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2609
Don\(aqt extract any data, just validate the JSON value against the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2610
given format string. Note that object keys must still be specified
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2611
after the format string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2612
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2613
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2614
Examples:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2615
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2616
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2617
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2618
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2619
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2620
/* root is the JSON integer 42 */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2621
int myint;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2622
json_unpack(root, "i", &myint);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2623
assert(myint == 42);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2624
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2625
/* root is the JSON object {"foo": "bar", "quux": true} */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2626
const char *str;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2627
int boolean;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2628
json_unpack(root, "{s:s, s:b}", "foo", &str, "quux", &boolean);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2629
assert(strcmp(str, "bar") == 0 && boolean == 1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2630
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2631
/* root is the JSON array [[1, 2], {"baz": null} */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2632
json_error_t error;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2633
json_unpack_ex(root, &error, JSON_VALIDATE_ONLY, "[[i,i], {s:n}]", "baz");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2634
/* returns 0 for validation success, nothing is extracted */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2635
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2636
/* root is the JSON array [1, 2, 3, 4, 5] */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2637
int myint1, myint2;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2638
json_unpack(root, "[ii!]", &myint1, &myint2);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2639
/* returns \-1 for failed validation */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2640
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2641
/* root is an empty JSON object */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2642
int myint = 0, myint2 = 0;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2643
json_unpack(root, "{s?i, s?[ii]}",
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2644
            "foo", &myint1,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2645
            "bar", &myint2, &myint3);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2646
/* myint1, myint2 or myint3 is no touched as "foo" and "bar" don\(aqt exist */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2647
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2648
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2649
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2650
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2651
.SS Equality
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2652
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2653
Testing for equality of two JSON values cannot, in general, be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2654
achieved using the \fB==\fP operator. Equality in the terms of the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2655
\fB==\fP operator states that the two \fBjson_t\fP pointers point to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2656
exactly the same JSON value. However, two JSON values can be equal not
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2657
only if they are exactly the same value, but also if they have equal
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2658
"contents":
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2659
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2660
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2661
Two integer or real values are equal if their contained numeric
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2662
values are equal. An integer value is never equal to a real value,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2663
though.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2664
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2665
Two strings are equal if their contained UTF\-8 strings are equal,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2666
byte by byte. Unicode comparison algorithms are not implemented.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2667
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2668
Two arrays are equal if they have the same number of elements and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2669
each element in the first array is equal to the corresponding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2670
element in the second array.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2671
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2672
Two objects are equal if they have exactly the same keys and the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2673
value for each key in the first object is equal to the value of the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2674
corresponding key in the second object.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2675
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2676
Two true, false or null values have no "contents", so they are equal
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2677
if their types are equal. (Because these values are singletons,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2678
their equality can actually be tested with \fB==\fP\&.)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2679
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2680
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2681
The following function can be used to test whether two JSON values are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2682
equal.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2683
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2684
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2685
.B int json_equal(json_t\fI\ *value1\fP, json_t\fI\ *value2\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2686
Returns 1 if \fIvalue1\fP and \fIvalue2\fP are equal, as defined above.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2687
Returns 0 if they are inequal or one or both of the pointers are
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2688
\fINULL\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2689
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2690
.SS Copying
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2691
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2692
Because of reference counting, passing JSON values around doesn\(aqt
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2693
require copying them. But sometimes a fresh copy of a JSON value is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2694
needed. For example, if you need to modify an array, but still want to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2695
use the original afterwards, you should take a copy of it first.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2696
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2697
Jansson supports two kinds of copying: shallow and deep. There is a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2698
difference between these methods only for arrays and objects. Shallow
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2699
copying only copies the first level value (array or object) and uses
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2700
the same child values in the copied value. Deep copying makes a fresh
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2701
copy of the child values, too. Moreover, all the child values are deep
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2702
copied in a recursive fashion.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2703
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2704
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2705
.B json_t *json_copy(json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2706
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2707
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2708
Returns a shallow copy of \fIvalue\fP, or \fINULL\fP on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2709
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2710
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2711
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2712
.B json_t *json_deep_copy(const json_t\fI\ *value\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2713
Return value: New reference.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2714
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2715
Returns a deep copy of \fIvalue\fP, or \fINULL\fP on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2716
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2717
.SS Custom Memory Allocation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2718
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2719
By default, Jansson uses \fBmalloc()\fP and \fBfree()\fP for
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2720
memory allocation. These functions can be overridden if custom
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2721
behavior is needed.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2722
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2723
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2724
.B json_malloc_t
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2725
A typedef for a function pointer with \fBmalloc()\fP\(aqs
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2726
signature:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2727
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2728
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2729
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2730
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2731
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2732
typedef void *(*json_malloc_t)(size_t);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2733
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2734
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2735
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2736
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2737
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2738
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2739
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2740
.B json_free_t
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2741
A typedef for a function pointer with \fBfree()\fP\(aqs
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2742
signature:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2743
.INDENT 7.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2744
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2745
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2746
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2747
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2748
typedef void (*json_free_t)(void *);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2749
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2750
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2751
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2752
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2753
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2754
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2755
.TP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2756
.B void json_set_alloc_funcs(json_malloc_t\fI\ malloc_fn\fP, json_free_t\fI\ free_fn\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2757
Use \fImalloc_fn\fP instead of \fBmalloc()\fP and \fIfree_fn\fP instead
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2758
of \fBfree()\fP\&. This function has to be called before any other
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2759
Jansson\(aqs API functions to ensure that all memory operations use
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2760
the same functions.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2761
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2762
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2763
\fBExamples:\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2764
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2765
Circumvent problems with different CRT heaps on Windows by using
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2766
application\(aqs \fBmalloc()\fP and \fBfree()\fP:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2767
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2768
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2769
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2770
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2771
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2772
json_set_alloc_funcs(malloc, free);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2773
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2774
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2775
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2776
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2777
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2778
Use the \fI\%Boehm\(aqs conservative garbage collector\fP for memory
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2779
operations:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2780
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2781
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2782
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2783
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2784
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2785
json_set_alloc_funcs(GC_malloc, GC_free);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2786
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2787
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2788
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2789
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2790
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2791
Allow storing sensitive data (e.g. passwords or encryption keys) in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2792
JSON structures by zeroing all memory when freed:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2793
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2794
.INDENT 3.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2795
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2796
.nf
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2797
.ft CW
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2798
static void *secure_malloc(size_t size)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2799
{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2800
    /* Store the memory area size in the beginning of the block */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2801
    void *ptr = malloc(size + 8);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2802
    *((size_t *)ptr) = size;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2803
    return ptr + 8;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2804
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2805
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2806
static void secure_free(void *ptr)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2807
{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2808
    size_t size;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2809
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2810
    ptr \-= 8;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2811
    size = *((size_t *)ptr);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2812
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2813
    guaranteed_memset(ptr, 0, size + 8);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2814
    free(ptr);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2815
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2816
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2817
int main()
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2818
{
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2819
    json_set_alloc_funcs(secure_malloc, secure_free);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2820
    /* ... */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2821
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2822
.ft R
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2823
.fi
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2824
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2825
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2826
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2827
For more information about the issues of storing sensitive data in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2828
memory, see
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2829
\fI\%http://www.dwheeler.com/secure\-programs/Secure\-Programs\-HOWTO/protect\-secrets.html\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2830
The page also explains the \fBguaranteed_memset()\fP function used
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2831
in the example and gives a sample implementation for it.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2832
.SS Changes in Jansson
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2833
.SS Version 2.7
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2834
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2835
Released 2014\-10\-02
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2836
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2837
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2838
New features:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2839
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2840
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2841
\fBjson_pack()\fP and friends: Add format specifiers \fBs%\fP and \fB+%\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2842
for a size_t string length (#141).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2843
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2844
\fBjson_unpack()\fP and friends: Add format specifier \fBs%\fP for
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2845
unpacking the string length along with the string itself (#141).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2846
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2847
Add length\-aware string constructors \fBjson_stringn()\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2848
\fBjson_stringn_nocheck()\fP, length\-aware string mutators
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2849
\fBjson_string_setn()\fP and \fBjson_string_setn_nocheck()\fP, and a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2850
function for getting string\(aqs length \fBjson_string_length()\fP (#141,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2851
#143).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2852
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2853
Support \fB\eu0000\fP escapes in the decoder. The support can be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2854
enabled by using the \fBJSON_ALLOW_NUL\fP decoding flag (#141).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2855
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2856
Add \fBjson_boolean_value()\fP as an alias for \fBjson_is_true()\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2857
(#146).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2858
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2859
Add JSON_REAL_PRECISION encoding flag/macro for controlling real
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2860
number precision (#178).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2861
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2862
Define the maximum indentation as JSON_MAX_INDENT (#191).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2863
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2864
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2865
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2866
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2867
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2868
Some malformed \fB\euNNNN\fP escapes could crash the decoder with an
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2869
assertion failure.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2870
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2871
Avoid integer overflows with very long strings in UTF\-8 decoder and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2872
hashtable.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2873
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2874
Check for \fINULL\fP key in \fBjson_object_get()\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2875
\fBjson_object_del()\fP (#151).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2876
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2877
Enhance hashtable seeding on Windows (#162).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2878
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2879
\fBjson_unpack()\fP: Allow mixing JSON_STRICT with optional keys
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2880
(#162, #163).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2881
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2882
Fix int/int32 mismatch (#142).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2883
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2884
Parse subnormal numbers correctly (#202).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2885
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2886
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2887
Build:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2888
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2889
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2890
Remove VS2010 build files. CMake should be used on Windows instead
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2891
(#165).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2892
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2893
Fix CMake build flags for MinGW (#193).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2894
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2895
Add CMake config files for find_package. Rename config.h to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2896
jansson_private_config.h (#157, #159).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2897
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2898
Make Valgrind checks work with CMake (#160).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2899
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2900
Fix feature checks to use correct __ATOMIC flags.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2901
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2902
Fix CMake checks for uint16_t and uint8_t support (#177).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2903
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2904
Make Jansson build on SmartOS/Solaris (#171).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2905
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2906
Work around a GCC bug on Solaris (#175).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2907
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2908
Fix autoreconf on Debian (#182).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2909
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2910
Don\(aqt use GNU make specific export for global AM_CFLAGS (#203,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2911
#204).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2912
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2913
Fix building on Android using the supplied Android.mk (#166,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2914
#174).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2915
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2916
Android.mk: Add \-DHAVE_STDINT_H to LOCAL_CFLAGS (#200).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2917
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2918
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2919
Documentation:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2920
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2921
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2922
Document JANSSON_BUILD_SHARED_LIBS CMake option (#187).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2923
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2924
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2925
Tests:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2926
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2927
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2928
Close file handles correctly (#198).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2929
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2930
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2931
Other changes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2932
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2933
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2934
\fB\euNNNN\fP escapes are now encoded in upper case for better
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2935
readability.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2936
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2937
Enable usage of AddressSanitizer (#180).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2938
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2939
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2940
.SS Version 2.6
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2941
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2942
Released 2014\-02\-11
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2943
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2944
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2945
Security:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2946
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2947
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2948
CVE\-2013\-6401: The hash function used by the hashtable
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2949
implementation has been changed, and is automatically seeded with
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2950
random data when the first JSON object is created. This prevents
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2951
an attacker from causing large JSON objects with specially crafted
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2952
keys perform poorly.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2953
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2954
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2955
New features:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2956
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2957
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2958
\fBjson_object_seed()\fP: Set the seed value of the hash function.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2959
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2960
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2961
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2962
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2963
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2964
Include CMake specific files in the release tarball.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2965
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2966
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2967
Documentation:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2968
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2969
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2970
Fix tutorial source to send a User\-Agent header, which is now
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2971
required by the GitHub API.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2972
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2973
Set all memory to zero in secure_free() example.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2974
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2975
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2976
.SS Version 2.5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2977
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2978
Released 2013\-09\-19
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2979
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2980
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2981
New features:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2982
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2983
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2984
\fBjson_pack()\fP and friends: Add format specifiers \fBs#\fP, \fB+\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2985
\fB+#\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2986
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2987
Add \fBJSON_DECODE_INT_AS_REAL\fP decoding flag to treat all numbers
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2988
as real in the decoder (#123).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2989
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2990
Add \fBjson_array_foreach()\fP, paralleling \fBjson_object_foreach()\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2991
(#118).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2992
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2993
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2994
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2995
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2996
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2997
\fBjson_dumps()\fP and friends: Don\(aqt crash if json is \fINULL\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2998
\fBJSON_ENCODE_ANY\fP is set.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  2999
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3000
Fix a theoretical integer overflow in \fBjsonp_strdup()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3001
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3002
Fix \fBl_isxdigit()\fP macro (#97).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3003
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3004
Fix an off\-by\-one error in \fBjson_array_remove()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3005
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3006
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3007
Build:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3008
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3009
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3010
Support CMake in addition to GNU Autotools (#106, #107, #112,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3011
#115, #120, #127).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3012
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3013
Support building for Android (#109).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3014
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3015
Don\(aqt use \fB\-Werror\fP by default.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3016
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3017
Support building and testing with VPATH (#93).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3018
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3019
Fix compilation when \fBNDEBUG\fP is defined (#128)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3020
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3021
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3022
Tests:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3023
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3024
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3025
Fix a refleak in \fBtest/bin/json_process.c\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3026
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3027
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3028
Documentation:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3029
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3030
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3031
Clarify the return value of \fBjson_load_callback_t()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3032
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3033
Document how to circumvent problems with separate heaps on Windows.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3034
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3035
Fix memory leaks and warnings in \fBgithub_commits.c\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3036
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3037
Use \fBjson_decref()\fP properly in tutorial.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3038
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3039
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3040
Other:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3041
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3042
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3043
Make it possible to forward declare \fBstruct json_t\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3044
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3045
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3046
.SS Version 2.4
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3047
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3048
Released 2012\-09\-23
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3049
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3050
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3051
New features:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3052
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3053
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3054
Add \fBjson_boolean()\fP macro that returns the JSON true or false
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3055
value based on its argument (#86).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3056
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3057
Add \fBjson_load_callback()\fP that calls a callback function
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3058
repeatedly to read the JSON input (#57).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3059
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3060
Add JSON_ESCAPE_SLASH encoding flag to escape all occurences of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3061
\fB/\fP with \fB\e/\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3062
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3063
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3064
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3065
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3066
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3067
Check for and reject NaN and Inf values for reals. Encoding these
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3068
values resulted in invalid JSON.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3069
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3070
Fix \fBjson_real_set()\fP to return \-1 on error.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3071
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3072
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3073
Build:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3074
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3075
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3076
Jansson now builds on Windows with Visual Studio 2010, and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3077
includes solution and project files in \fBwin32/vs2010/\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3078
directory.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3079
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3080
Fix build warnings (#77, #78).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3081
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3082
Add \fB\-no\-undefined\fP to LDFLAGS (#90).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3083
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3084
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3085
Tests:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3086
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3087
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3088
Fix the symbol exports test on Linux/PPC64 (#88).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3089
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3090
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3091
Documentation:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3092
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3093
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3094
Fix typos (#73, #84).
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3095
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3096
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3097
.SS Version 2.3.1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3098
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3099
Released 2012\-04\-20
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3100
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3101
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3102
Build issues:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3103
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3104
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3105
Only use \fBlong long\fP if \fBstrtoll()\fP is also available.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3106
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3107
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3108
Documentation:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3109
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3110
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3111
Fix the names of library version constants in documentation. (#52)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3112
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3113
Change the tutorial to use GitHub API v3. (#65)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3114
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3115
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3116
Tests:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3117
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3118
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3119
Make some tests locale independent. (#51)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3120
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3121
Distribute the library exports test in the tarball.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3122
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3123
Make test run on shells that don\(aqt support the \fBexport FOO=bar\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3124
syntax.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3125
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3126
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3127
.SS Version 2.3
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3128
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3129
Released 2012\-01\-27
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3130
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3131
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3132
New features:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3133
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3134
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3135
\fBjson_unpack()\fP and friends: Add support for optional object keys
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3136
with the \fB{s?o}\fP syntax.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3137
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3138
Add \fBjson_object_update_existing()\fP and
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3139
\fBjson_object_update_missing()\fP, for updating only existing keys or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3140
only adding missing keys to an object. (#37)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3141
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3142
Add \fBjson_object_foreach()\fP for more convenient iteration over
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3143
objects. (#45, #46)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3144
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3145
When decoding JSON, write the number of bytes that were read from
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3146
input to \fBerror.position\fP also on success. This is handy with
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3147
\fBJSON_DISABLE_EOF_CHECK\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3148
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3149
Add support for decoding any JSON value, not just arrays or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3150
objects. The support is enabled with the new \fBJSON_DECODE_ANY\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3151
flag. Patch by Andrea Marchesini. (#4)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3152
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3153
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3154
Bug fixes
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3155
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3156
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3157
Avoid problems with object\(aqs serial number growing too big. (#40,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3158
#41)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3159
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3160
Decoding functions now return NULL if the first argument is NULL.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3161
Patch by Andrea Marchesini.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3162
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3163
Include \fBjansson_config.h.win32\fP in the distribution tarball.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3164
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3165
Remove \fB+\fP and leading zeros from exponents in the encoder.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3166
(#39)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3167
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3168
Make Jansson build and work on MinGW. (#39, #38)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3169
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3170
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3171
Documentation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3172
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3173
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3174
Note that the same JSON values must not be encoded in parallel by
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3175
separate threads. (#42)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3176
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3177
Document MinGW support.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3178
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3179
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3180
.SS Version 2.2.1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3181
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3182
Released 2011\-10\-06
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3183
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3184
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3185
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3186
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3187
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3188
Fix real number encoding and decoding under non\-C locales. (#32)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3189
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3190
Fix identifier decoding under non\-UTF\-8 locales. (#35)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3191
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3192
\fBjson_load_file()\fP: Open the input file in binary mode for maximum
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3193
compatiblity.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3194
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3195
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3196
Documentation:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3197
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3198
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3199
Clarify the lifecycle of the result of the \fBs\fP fromat of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3200
\fBjson_unpack()\fP\&. (#31)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3201
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3202
Add some portability info. (#36)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3203
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3204
Little clarifications here and there.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3205
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3206
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3207
Other:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3208
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3209
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3210
Some style fixes, issues detected by static analyzers.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3211
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3212
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3213
.SS Version 2.2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3214
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3215
Released 2011\-09\-03
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3216
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3217
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3218
New features:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3219
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3220
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3221
\fBjson_dump_callback()\fP: Pass the encoder output to a callback
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3222
function in chunks.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3223
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3224
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3225
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3226
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3227
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3228
\fBjson_string_set()\fP: Check that target is a string and value is
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3229
not NULL.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3230
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3231
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3232
Other:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3233
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3234
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3235
Documentation typo fixes and clarifications.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3236
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3237
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3238
.SS Version 2.1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3239
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3240
Released 2011\-06\-10
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3241
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3242
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3243
New features:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3244
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3245
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3246
\fBjson_loadb()\fP: Decode a string with a given size, useful if the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3247
string is not null terminated.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3248
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3249
Add \fBJSON_ENCODE_ANY\fP encoding flag to allow encoding any JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3250
value. By default, only arrays and objects can be encoded. (#19)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3251
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3252
Add \fBJSON_REJECT_DUPLICATES\fP decoding flag to issue a decoding
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3253
error if any JSON object in the input contins duplicate keys. (#3)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3254
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3255
Add \fBJSON_DISABLE_EOF_CHECK\fP decoding flag to stop decoding after a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3256
valid JSON input. This allows other data after the JSON data.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3257
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3258
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3259
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3260
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3261
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3262
Fix an additional memory leak when memory allocation fails in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3263
\fBjson_object_set()\fP and friends.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3264
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3265
Clear errno before calling \fBstrtod()\fP for better portability. (#27)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3266
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3267
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3268
Building:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3269
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3270
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3271
Avoid set\-but\-not\-used warning/error in a test. (#20)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3272
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3273
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3274
Other:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3275
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3276
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3277
Minor clarifications to documentation.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3278
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3279
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3280
.SS Version 2.0.1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3281
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3282
Released 2011\-03\-31
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3283
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3284
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3285
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3286
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3287
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3288
Replace a few \fBmalloc()\fP and \fBfree()\fP calls with their
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3289
counterparts that support custom memory management.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3290
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3291
Fix object key hashing in json_unpack() strict checking mode.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3292
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3293
Fix the parentheses in \fBJANSSON_VERSION_HEX\fP macro.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3294
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3295
Fix \fBjson_object_size()\fP return value.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3296
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3297
Fix a few compilation issues.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3298
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3299
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3300
Portability:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3301
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3302
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3303
Enhance portability of \fBva_copy()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3304
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3305
Test framework portability enhancements.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3306
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3307
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3308
Documentation:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3309
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3310
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3311
Distribute \fBdoc/upgrading.rst\fP with the source tarball.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3312
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3313
Build documentation in strict mode in \fBmake distcheck\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3314
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3315
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3316
.SS Version 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3317
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3318
Released 2011\-02\-28
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3319
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3320
This release is backwards incompatible with the 1.x release series.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3321
See the chapter "Upgrading from older versions" in documentation for
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3322
details.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3323
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3324
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3325
Backwards incompatible changes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3326
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3327
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3328
Unify unsigned integer usage in the API: All occurences of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3329
unsigned int and unsigned long have been replaced with size_t.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3330
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3331
Change JSON integer\(aqs underlying type to the widest signed integer
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3332
type available, i.e. long long if it\(aqs supported, otherwise long.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3333
Add a typedef json_int_t that defines the type.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3334
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3335
Change the maximum indentation depth to 31 spaces in encoder. This
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3336
frees up bits from the flags parameter of encoding functions
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3337
\fBjson_dumpf()\fP, \fBjson_dumps()\fP and \fBjson_dump_file()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3338
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3339
For future needs, add a flags parameter to all decoding functions
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3340
\fBjson_loadf()\fP, \fBjson_loads()\fP and \fBjson_load_file()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3341
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3342
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3343
New features
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3344
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3345
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3346
\fBjson_pack()\fP, \fBjson_pack_ex()\fP, \fBjson_vpack_ex()\fP: Create JSON
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3347
values based on a format string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3348
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3349
\fBjson_unpack()\fP, \fBjson_unpack_ex()\fP, \fBjson_vunpack_ex()\fP: Simple
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3350
value extraction and validation functionality based on a format
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3351
string.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3352
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3353
Add column, position and source fields to the \fBjson_error_t\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3354
struct.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3355
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3356
Enhance error reporting in the decoder.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3357
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3358
\fBJANSSON_VERSION\fP et al.: Preprocessor constants that define the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3359
library version.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3360
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3361
\fBjson_set_alloc_funcs()\fP: Set custom memory allocation functions.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3362
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3363
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3364
Fix many portability issues, especially on Windows.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3365
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3366
Configuration
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3367
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3368
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3369
Add file \fBjansson_config.h\fP that contains site specific
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3370
configuration. It\(aqs created automatically by the configure script,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3371
or can be created by hand if the configure script cannot be used.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3372
The file \fBjansson_config.h.win32\fP can be used without
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3373
modifications on Windows systems.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3374
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3375
Add a section to documentation describing how to build Jansson on
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3376
Windows.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3377
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3378
Documentation now requires Sphinx 1.0 or newer.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3379
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3380
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3381
.SS Version 1.3
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3382
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3383
Released 2010\-06\-13
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3384
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3385
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3386
New functions:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3387
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3388
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3389
\fBjson_object_iter_set()\fP, \fBjson_object_iter_set_new()\fP: Change
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3390
object contents while iterating over it.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3391
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3392
\fBjson_object_iter_at()\fP: Return an iterator that points to a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3393
specific object item.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3394
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3395
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3396
New encoding flags:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3397
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3398
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3399
\fBJSON_PRESERVE_ORDER\fP: Preserve the insertion order of object
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3400
keys.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3401
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3402
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3403
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3404
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3405
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3406
Fix an error that occured when an array or object was first
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3407
encoded as empty, then populated with some data, and then
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3408
re\-encoded
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3409
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3410
Fix the situation like above, but when the first encoding resulted
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3411
in an error
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3412
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3413
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3414
Documentation:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3415
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3416
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3417
Clarify the documentation on reference stealing, providing an
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3418
example usage pattern
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3419
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3420
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3421
.SS Version 1.2.1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3422
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3423
Released 2010\-04\-03
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3424
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3425
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3426
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3427
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3428
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3429
Fix reference counting on \fBtrue\fP, \fBfalse\fP and \fBnull\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3430
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3431
Estimate real number underflows in decoder with 0.0 instead of
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3432
issuing an error
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3433
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3434
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3435
Portability:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3436
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3437
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3438
Make \fBint32_t\fP available on all systems
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3439
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3440
Support compilers that don\(aqt have the \fBinline\fP keyword
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3441
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3442
Require Autoconf 2.60 (for \fBint32_t\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3443
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3444
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3445
Tests:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3446
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3447
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3448
Print test names correctly when \fBVERBOSE=1\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3449
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3450
\fBtest/suites/api\fP: Fail when a test fails
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3451
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3452
Enhance tests for iterators
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3453
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3454
Enhance tests for decoding texts that contain null bytes
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3455
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3456
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3457
Documentation:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3458
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3459
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3460
Don\(aqt remove \fBchanges.rst\fP in \fBmake clean\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3461
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3462
Add a chapter on RFC conformance
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3463
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3464
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3465
.SS Version 1.2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3466
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3467
Released 2010\-01\-21
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3468
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3469
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3470
New functions:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3471
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3472
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3473
\fBjson_equal()\fP: Test whether two JSON values are equal
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3474
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3475
\fBjson_copy()\fP and \fBjson_deep_copy()\fP: Make shallow and deep copies
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3476
of JSON values
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3477
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3478
Add a version of all functions taking a string argument that
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3479
doesn\(aqt check for valid UTF\-8: \fBjson_string_nocheck()\fP,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3480
\fBjson_string_set_nocheck()\fP, \fBjson_object_set_nocheck()\fP,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3481
\fBjson_object_set_new_nocheck()\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3482
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3483
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3484
New encoding flags:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3485
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3486
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3487
\fBJSON_SORT_KEYS\fP: Sort objects by key
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3488
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3489
\fBJSON_ENSURE_ASCII\fP: Escape all non\-ASCII Unicode characters
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3490
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3491
\fBJSON_COMPACT\fP: Use a compact representation with all unneeded
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3492
whitespace stripped
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3493
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3494
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3495
Bug fixes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3496
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3497
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3498
Revise and unify whitespace usage in encoder: Add spaces between
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3499
array and object items, never append newline to output.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3500
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3501
Remove const qualifier from the \fBjson_t\fP parameter in
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3502
\fBjson_string_set()\fP, \fBjson_integer_set()\fP and \fBjson_real_set()\fP\&.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3503
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3504
Use \fBint32_t\fP internally for representing Unicode code points
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3505
(int is not enough on all platforms)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3506
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3507
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3508
Other changes:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3509
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3510
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3511
Convert \fBCHANGES\fP (this file) to reStructured text and add it to
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3512
HTML documentation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3513
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3514
The test system has been refactored. Python is no longer required
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3515
to run the tests.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3516
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3517
Documentation can now be built by invoking \fBmake html\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3518
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3519
Support for pkg\-config
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3520
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3521
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3522
.SS Version 1.1.3
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3523
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3524
Released 2009\-12\-18
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3525
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3526
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3527
Encode reals correctly, so that first encoding and then decoding a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3528
real always produces the same value
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3529
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3530
Don\(aqt export private symbols in \fBlibjansson.so\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3531
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3532
.SS Version 1.1.2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3533
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3534
Released 2009\-11\-08
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3535
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3536
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3537
Fix a bug where an error message was not produced if the input file
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3538
could not be opened in \fBjson_load_file()\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3539
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3540
Fix an assertion failure in decoder caused by a minus sign without a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3541
digit after it
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3542
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3543
Remove an unneeded include of \fBstdint.h\fP in \fBjansson.h\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3544
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3545
.SS Version 1.1.1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3546
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3547
Released 2009\-10\-26
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3548
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3549
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3550
All documentation files were not distributed with v1.1; build
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3551
documentation in make distcheck to prevent this in the future
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3552
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3553
Fix v1.1 release date in \fBCHANGES\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3554
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3555
.SS Version 1.1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3556
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3557
Released 2009\-10\-20
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3558
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3559
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3560
API additions and improvements:
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3561
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3562
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3563
Extend array and object APIs
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3564
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3565
Add functions to modify integer, real and string values
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3566
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3567
Improve argument validation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3568
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3569
Use unsigned int instead of \fBuint32_t\fP for encoding flags
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3570
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3571
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3572
Enhance documentation
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3573
.INDENT 2.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3574
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3575
Add getting started guide and tutorial
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3576
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3577
Fix some typos
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3578
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3579
General clarifications and cleanup
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3580
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3581
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3582
Check for integer and real overflows and underflows in decoder
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3583
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3584
Make singleton values thread\-safe (\fBtrue\fP, \fBfalse\fP and \fBnull\fP)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3585
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3586
Enhance circular reference handling
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3587
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3588
Don\(aqt define \fB\-std=c99\fP in \fBAM_CFLAGS\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3589
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3590
Add C++ guards to \fBjansson.h\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3591
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3592
Minor performance and portability improvements
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3593
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3594
Expand test coverage
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3595
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3596
.SS Version 1.0.4
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3597
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3598
Released 2009\-10\-11
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3599
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3600
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3601
Relax Autoconf version requirement to 2.59
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3602
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3603
Make Jansson compile on platforms where plain \fBchar\fP is unsigned
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3604
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3605
Fix API tests for object
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3606
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3607
.SS Version 1.0.3
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3608
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3609
Released 2009\-09\-14
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3610
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3611
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3612
Check for integer and real overflows and underflows in decoder
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3613
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3614
Use the Python json module for tests, or simplejson if the json
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3615
module is not found
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3616
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3617
Distribute changelog (this file)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3618
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3619
.SS Version 1.0.2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3620
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3621
Released 2009\-09\-08
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3622
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3623
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3624
Handle EOF correctly in decoder
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3625
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3626
.SS Version 1.0.1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3627
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3628
Released 2009\-09\-04
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3629
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3630
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3631
Fixed broken \fBjson_is_boolean()\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3632
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3633
.SS Version 1.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3634
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3635
Released 2009\-08\-25
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3636
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3637
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3638
Initial release
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3639
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3640
.INDENT 0.0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3641
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3642
\fIgenindex\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3643
.IP \(bu 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3644
\fIsearch\fP
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3645
.UNINDENT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3646
.sp
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3647
.SH AUTHOR
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3648
Petri Lehtinen
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3649
.SH COPYRIGHT
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3650
2009-2014, Petri Lehtinen
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3651
.\" Generated by docutils manpage writer.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
  3652
.