glenda.party
term% ls -F
term% pwd
$home/manuals/9front/2/json
term% cat index.txt
JSON(2)                       System Calls Manual                      JSON(2)



NAME
       jsonparse, jsonfree, jsonbyname, jsonstr - JSON parser

SYNOPSIS
       #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 *);

DESCRIPTION
       The JSON structure represents a variant json value. The variant type is
       stored in the t member of the structure. String values use s,  booleans
       and  numbers  use  the  n members in the structure.  Arrays and objects
       (dictionaries) are represented by a singly-linked list of JSONEl strucā€
       tures  referred  to from the first pointer in the JSON structure.  Each
       JSONEl has a val pointer to the associated value and a next pointer  to
       the  next  element in the array or object.  Dictionary objects have the
       name member set to the key of the association.

       A json object is parsed by calling jsonparse with a UTF-8 string of the
       json  encoded  data. On success, a non-nil pointer to a newly allocated
       JSON structure is returned.  To free the parsed objects,  jsonfree  has
       to be called.

       The  jsonbyname  function  returns the associated value of a dictionary
       item.

       The function jsonstr returns the string value of a json object  or  nil
       for any other object type.

SOURCE
       /sys/src/libjson

DIAGNOSTICS
       The functions jsonparse, jsonbyname and jsonstr return nil on error and
       set an error string (see errstr(2)).



                                                                       JSON(2)