From 54f637a9a85e842e1d691e9f96a1c6c25ccd7d9c Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 7 Feb 2014 18:11:36 -0800 Subject: [PATCH] More documentation of object internals --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++-- jsonpull.h | 2 +- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f1fc162..e1b75fe 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,7 @@ Reading single JSON objects The simplest form is json_read_tree(), which reads a complete JSON object from the stream, or NULL if there was an error or on end of file. -Call json_free() on the object when you are done with it, -and json_end() on the parser. +Call json_free() on the object when you are done with it. You can continue calling json_read_tree() to read additional objects from the same stream. This is not standard JSON, but is useful for something like @@ -66,3 +65,47 @@ purpose there is an additional streaming reader function, a function to call when brackets, braces, commas, and colons are read. Other object types and the closing of arrays and hashes are still sent through the normal return value. + +The types that can be sent to the callback function are +JSON_ARRAY, JSON_HASH, JSON_COMMA, +and JSON_COLON. + +Shutdown +-------- + +To free the parser object, call json_end() on it. + +Object format +------------- + +JSON objects are represented as the C struct json_object. +It contains a type field to indicate its type, a parent +pointer to the container that encloses it, and additional fields per type. + +Types JSON_NULL, JSON_TRUE, and JSON_FALSE +have no additional data. + +Strings have type JSON_STRING, with null-terminated UTF-8 text +in string and length in length. + +Numbers have type JSON_NUMBER, with value in number. + +Arrays have type JSON_ARRAY. There are length elements in the array, +and the elements are in array. + +Hashes have type JSON_HASH. There are length key-value pairs, +and the keys are in keys and the values in values. + +Parser format +------------- + +The parser object has two fields of public interest: error is a string +describing any errors found in the JSON, and line is the current line number +being read from the input to make it easier to find the errors. + +Utility function +---------------- + +There is a function json_hash_get that looks up the JSON object hash value +corresponding to a C string hash key in a JSON hash object. If the object specified is +NULL or not a JSON hash or has no matching key, it returns NULL. diff --git a/jsonpull.h b/jsonpull.h index 6e14d6a..64010f8 100644 --- a/jsonpull.h +++ b/jsonpull.h @@ -26,11 +26,11 @@ typedef struct json_object { typedef struct json_pull { char *error; + int line; int (*read)(struct json_pull *); int (*peek)(struct json_pull *); void *source; - int line; json_object *container; } json_pull;