diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2013-12-19 19:56:04 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2013-12-19 19:56:04 +0100 |
commit | 803bc88a5f3f5835bc57fdeb8f2f96c9a8ce5ab3 (patch) | |
tree | 9bc6f8a861fa756809280e904fae169edbae7b04 | |
parent | 56300f72e8cd3d7c8dcf75173cb0234c22196c37 (diff) | |
download | plan9front-803bc88a5f3f5835bc57fdeb8f2f96c9a8ce5ab3.tar.xz |
add medium to low quality json(2) manual page
-rw-r--r-- | sys/man/2/json | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/sys/man/2/json b/sys/man/2/json new file mode 100644 index 000000000..9fdbd3950 --- /dev/null +++ b/sys/man/2/json @@ -0,0 +1,110 @@ +.TH JSON 2 +.SH NAME +jsonparse, +jsonfree, +jsonbyname, +jsonstr +\- JSON parser +.SH SYNOPSIS +.\" .ta 0.75i 1.5i 2.25i 3i 3.75i 4.5i +.ta 0.7i +0.7i +0.7i +0.7i +0.7i +0.7i +0.7i +.EX +#include <u.h> +#include <libc.h> +#include <json.h> + +enum { + JSONNull, + JSONBool, + JSONNumber, + JSONString, + JSONArray, + JSONObject, +}; + +typedef struct JSONEl JSONEl; +struct JSONEl { + char *name; + JSON *val; + JSONEl *next; +}; + +typedef struct JSON JSON; +struct JSON +{ + int t; + union { + double n; + char *s; + JSONEl *first; + }; +}; + +JSON* jsonparse(char *); +void jsonfree(JSON *); +JSON* jsonbyname(JSON *, char *); +char* jsonstr(JSON *); +.EE +.SH DESCRIPTION +The +.B JSON +structure represents a variant json value. The variant type +is stored in the +.I t +member of the structure. String values use +.BR s , +booleans and numbers use the +.B n +members in the structure. +Arrays and objects (dictionaries) are represented by +a singly-linked list of +.B JSONEl +structures refered to from the +.B first +pointer in the +.B JSON +structure. +Each +.B JSONEl +has a +.B val +pointer to the associated value and a +.B next +pointer to the next element in the array or object. +Dictionary objects have the +.B name +member set to the key of the association. +.P +A json object is parsed by calling +.B jsonparse +with a +.B UTF-8 +string of the json encoded data. On success, a non-nil pointer to a +newly allocated +.B JSON +structure is returned. +To free the parsed objects, +.B jsonfree +has to be called. +.P +The +.B jsonbyname +function returns the associated value of a dictionary item. +.P +The function +.B jsonstr +returns the string value of a json object or +.B nil +for any other object type. +.SH DIAGNOSTICS +The functions +.IB jsonparse , +.B jsonbyname +and +.B jsonstr +return +.B nil +on error and set an error string (see +.IR errstr (2)). +.SH SOURCE +.B /sys/src/libjson |