v3.1.0 API Documentation
Types Globals Functions
Introduction

Optimized JSON in C (OjC), as the name implies, was written to provide speed optimized JSON handling. It is derived from the underlying C parser in [Oj](http://www.ohler.com/oj). The intended use is for applications that need the maximum performance when reading large JSON document from a file or socket.

Besides being a true streaming parser OjC produces a structure that handles all JSON constructs. It does not use a Hash or Map to represent the JSON object type but keeps all occurances of a pairs in the object element. Duplicates are allowed just as they are in JSON documents.

Multiple JSON elements are allowed in a single stream or from a socket. A callback mechanism is provided to return full JSON elements for each entry in a JSON stream.

Guides

Simple JSON Parsing Example

typedef enum {include "ojc/ojc.h" void sample() { char buf[256]; ojcVal val; struct _ojcErr err; const char *json = "[null,true,\"word\",{\"a\":1234}"; ojc_err_init(&err); // no callback val = ojc_parse_str(&err, json, 0, 0); ojc_fill(&err, val, 0, buf, sizeof(buf)); if (OJC_OK != err) { printf("error: %s\n", err.msg); return; } printf("parsed json '%s'\n", buf); ojc_destroy(val); }

Callback JSON Parsing Example

typedef enum {include "ojc/ojc.h" static bool each__callback(ojcVal val, void *ctx) { char buf[64]; struct _ojcErr err; ojc_err_init(&err); ojc_fill(&err, val, 0, buf, sizeof(buf)); if (OJC_OK != err) { printf("error: %s\n", err.msg); } else { printf("parsed json '%s'\n", buf); } return true; } void sample() { struct _ojcErr err; const char *json = "{\"a\":111} {\"b\":222} {\"c\":333}"; ojc_err_init(&err); ojc_parse_str(&err, json, each_callback, 0); if (OJC_OK != err) { printf("error: %s\n", err.msg); } }
ojcErr
typedef struct _ojcErr { int code; char msg[256]; } *ojcErr;

The struct used to report errors or status after a function returns. The struct must be initialized before use as most calls that take an err argument will return immediately if an error has already occurred.

codeError code identifying the type of error.
msgError message associated with a failure if the code is not OJC_OK.
See:ojcErrCode
ojcErrCode
typedef enum { OJC_OK = 0, OJC_TYPE_ERR = 't', OJC_PARSE_ERR = 'p', OJC_INCOMPLETE_ERR = 'i', OJC_OVERFLOW_ERR = 'o', OJC_WRITE_ERR = 'w', OJC_MEMORY_ERR = 'm', OJC_UNICODE_ERR = 'u', OJC_ABORT_ERR = '@', OJC_ARG_ERR = 'a', } ojcErrCode;

Error codes for the code field in ojcErr structs.

OJC_OKokay, no error
OJC_TYPE_ERRtype error
OJC_PARSE_ERRparse error
OJC_INCOMPLETE_ERRincomplete parse error
OJC_OVERFLOW_ERRbuffer overflow error
OJC_WRITE_ERRwrite error
OJC_MEMORY_ERRmemory error
OJC_UNICODE_ERRunicode error
OJC_ABORT_ERRabort callback parsing
OJC_ARG_ERRargument error
See:ojcErr
ojcParseCallback
typedef bool (*ojcParseCallback)(ojcErr err, ojcVal val, void *ctx);

When using the parser callbacks, the callback must be of this type. The arguments will be the context provided when calling the parser and the value extracted from the JSON stream.

A return value of true indicates the parser should free the values after the callback returns. If the return value is false then the callback is responsible for freeing the value when no longer needed.

errerror to be filled in if an error occurs
valmessages parsed
ctxcontext provided in the call to parse
See:ojc_parse_str, ojc_parse_file, ojc_parse_fd
ojcReadFunc
typedef ssize_t (*ojcReadFunc)(void *src, char *buf, size_t size);

Function type to use when providing a custom reader to the parser. Useful for hooking up zlib or similar libraries.

srcsource
bufbuffer to fill
sizemaximum size to place in the buffer
See:ojc_parse_reader
ojcVal
typedef struct _ojcVal *ojcVal;

The type representing a value in a JSON file. Values will be one of the ojcValType enum.

See:ojcValType
ojcValType
typedef enum { OJC_NULL = 0, OJC_STRING = 's', OJC_NUMBER = 'N', OJC_FIXNUM = 'n', OJC_DECIMAL = 'd', OJC_TRUE = 't', OJC_FALSE = 'f', OJC_ARRAY = 'a', OJC_OBJECT = 'o', OJC_WORD = 'w', OJC_OPAQUE = 'i', OJC_FREE = '#', } ojcValType;

The value types found in JSON documents and in the ojcVal type.

srcsource
OJC_NULLnull
OJC_STRINGstring
OJC_NUMBERnumber as a string
OJC_FIXNUMinteger
OJC_DECIMALdecimal number
OJC_TRUEtrue
OJC_FALSEfalse
OJC_ARRAYarray
OJC_OBJECTobject
OJC_WORDword with a maximum of 15 characters
OJC_OPAQUEopaque which is ignored on write
OJC_FREEfreed
See:ojcVal
ojc_case_insensitive
bool ojc_case_insensitive;

If true, searches are case insensitive. Searches includes get and replace operations.

ojc_decimal_as_number
bool ojc_decimal_as_number;

If true, decimal numbers will be read as OJC_NUMBER instead of as a OJC_DECIMAL.

ojc_newline_ok
bool ojc_newline_ok;

If true, new lines will not be escaped in the output. This is not a JSON feature.

ojc_word_ok
bool ojc_word_ok;

If true, non-quoted word will be returned as OJC_WORD types. This is not a JSON feature.

ojc_write_end_with_newline
bool ojc_write_end_with_newline;

If true, a write is terminated with a new line.

ojc_write_opaque
bool ojc_write_opaque;

If true, opaque values will be printed as a number. Note that reading in this value will from a JSON string will result in a OJC_FIXNUM type. This flag is intended for debugging and should be set back to false after printing.

ojc_aappend()
void ojc_aappend(ojcErr err, ojcVal anchor, const char **path, ojcVal val);

Appends an ojcVal at the provided path where the path is a NULL terminated array of strings that are keys or indices that form a path to a target value. If any node does not exist on the path an Object is created for that element of the path.

errpointer to an initialized ojcErr struct.
anchoranchor value for locating the target value
pathlocation of the target value relative to the anchor
valvalue to place at the target location
ojc_aget()
ojcVal ojc_aget(ojcVal val, const char **path);

Gets an ojcVal located by the provided path where the path is a NULL terminated array of strings that are keys or indices that form a path to a target value. If the element does not exist a NULL value is returned. A NULL path returns the val argument.

valanchor value for locating the target value
pathlocation of the target value
Returns:the value identified by the path or NULL if it does not exist.
ojc_append()
void ojc_append(ojcErr err, ojcVal anchor, const char *path, ojcVal val);

Appends an ojcVal at the provided path where the path is a sequence of keys or indices separated by the / or . character. If any node does not exist on the path an Object or Array is created for that element of the path.

errpointer to an initialized ojcErr struct.
anchoranchor value for locating the target value
pathlocation of the target value relative to the anchor
valvalue to place at the target location
ojc_aremove()
bool ojc_aremove(ojcErr err, ojcVal anchor, const char **path);

Removes an ojcVal at the provided path where the path is a NULL terminated array of strings that are keys or indices that form a path to a target value.

errpointer to an initialized ojcErr struct.
anchoranchor value for locating the target value
pathlocation of the target value
Returns:true if a value was removed and false if it was not.
ojc_areplace()
bool ojc_areplace(ojcErr err, ojcVal anchor, const char **path, ojcVal val);

Replaces of appends an ojcVal at the provided path where the path is a NULL terminated array of strings that are keys or indices that form a path to a target value. If any node does not exist on the path an Object is created for that element of the path.

errpointer to an initialized ojcErr struct.
anchoranchor value for locating the target value
pathlocation of the target value
valvalue to place at the target location
Returns:true if a value was replaced and false if it was appended.
ojc_array_append()
void ojc_array_append(ojcErr err, ojcVal array, ojcVal val);

Appends a val to a JSON array. The err struct is set if the object is not an OJCARRAY type.

errpointer to an initialized ojcErr struct.
arrayarray to append val to
valvalue to append
ojc_array_insert()
void ojc_array_insert(ojcErr err, ojcVal array, int pos, ojcVal val);

Inserts a val in a JSON array before the pos. The err struct is set if the array is not an OJCARRAY type.

errpointer to an initialized ojcErr struct.
arrayarray to insert val into
posposition to insert the new value
valnew value
ojc_array_pop()
ojcVal ojc_array_pop(ojcErr err, ojcVal array);

Removes and returns a val from the front of a JSON array. The err struct is set if the object is not an OJCARRAY type.

errpointer to an initialized ojcErr struct.
arrayarray to append val to
Returns:the first element in an array.
ojc_array_push()
void ojc_array_push(ojcErr err, ojcVal array, ojcVal val);

Pushes a val to the front of a JSON array. The err struct is set if the object is not an OJCARRAY type.

errpointer to an initialized ojcErr struct.
arrayarray to append val to
valvalue to push
ojc_array_replace()
bool ojc_array_replace(ojcErr err, ojcVal array, int pos, ojcVal val);

Replaces a val in a JSON object for the specified pos. The err struct is set if the array is not an OJCARRAY type. If the pos is negative the position is counted from the end of the array unless the value is less than the length of the array and then it is pushed onto the array. If the pos is larger than the length the val is appended to the array.

errpointer to an initialized ojcErr struct.
arrayarray to replace the value with val
posthe position of the value to replace in the array
valnew value
Returns:true if a value was replaced and false if it was pushed or appended.
ojc_areplace()
bool ojc_aset(ojcErr err, ojcVal anchor, const char **path, ojcVal val);

Replaces of appends an ojcVal at the provided path where the path is a NULL terminated array of strings that are keys or indices that form a path to a target value. If any node does not exist on the path an Object is created for that element of the path.

errpointer to an initialized ojcErr struct.
anchoranchor value for locating the target value
pathlocation of the target value
valvalue to place at the target location
Returns:true if a value was replaced and false if it was appended.
ojc_bool()
bool ojc_bool(ojcErr err, ojcVal val);

Get the boolean value of a ojcVal if it is of type OJC_TRUE or OJC_FALSE. If it is not the correct type a type error is returned in the err value.

errstructure to pass the status or an error back in
valojcVal to get the boolean from
Returns:the boolean value of the val argument.
ojc_buf()
void ojc_buf(struct _Buf *buf, ojcVal val, int indent, int depth);

Fills a Buf with val as a JSON formated string in the buffer provided. The indent argument is used indentation of elements in the output.

bufpointer to an Buf struct.
valojcVal to convert to JSON
indentindentation in spaces to use
depthinitial indentaion depth
ojc_cleanup()
void ojc_cleanup();

Cleans up re-use memory pools.

ojc_cmp()
int ojc_cmp(ojcVal v1, ojcVal v2);

Returns an integer greater than, equal to, or less than zero according if v1 is greater than, equal to, or less than v2. A best effort is made to compare dissimilar type.

v1ojcVal an object to compare.
v2ojcVal an object to compare.
Returns:the result of the comparison.
ojc_create_array()
ojcVal ojc_create_array(void);

Creates a JSON array value.

Returns:the new array value.
ojc_create_bool()
ojcVal ojc_create_bool(bool boo);

Creates a boolean value or either true or false.

boovalue of the new instance
Returns:the new boolean value.
ojc_create_double()
ojcVal ojc_create_double(double num);

Creates a double value.

numvalue of the new instance
Returns:the new double value.
ojc_create_int()
ojcVal ojc_create_int(int64_t num);

Creates a integer value.

numvalue of the new instance
Returns:the new integer value.
ojc_create_null()
ojcVal ojc_create_null();

Creates a null value.

Returns:the new null value.
ojc_create_number()
ojcVal ojc_create_number(const char *num, size_t len);

Creates a number value that is represented as a string. This value type is created when a number is encountered in a JSON document that is too large for an int64_t or for a double.

numvalue of the new instance
lenlength of str or <0 to calculate
Returns:the new numeric string value.
ojc_create_object()
ojcVal ojc_create_object();

Creates a JSON object value.

Returns:the new object value.
ojc_create_opaque()
ojcVal ojc_create_opaque(void *opaque);

Creates an opaque value.

opaquevalue of the new instance
Returns:the new value.
ojc_create_str()
ojcVal ojc_create_str(const char *str, size_t len);

Creates a string value.

strvalue of the new instance
lenlength of str or <0 to calculate
Returns:the new string value.
ojc_create_word()
ojcVal ojc_create_word(const char *str, size_t len);

Creates a word value.

strvalue of the new instance
lenlength of str or <0 to calculate
Returns:the new word value.
ojc_destroy()
int ojc_destroy(ojcVal val);

Frees memory used by a ojcVal.

valvalue to free or destroy.
Returns:0 on success or non-zero if already freed.
ojc_double()
double ojc_double(ojcErr err, ojcVal val);

Get the decimal (double) value of a ojcVal if it is of type OJC_DECIMAL. If it is not the correct type a type error is returned in the err value.

errstructure to pass the status or an error back in
valojcVal to get the C double from
Returns:the C double value of the val argument.
ojc_duplicate()
ojcVal ojc_duplicate(ojcVal val);

Returns a deep copy of a ojcVal.

valojcVal to duplicate.
Returns:a deep copy of the val.
ojc_equals()
bool ojc_equals(ojcVal v1, ojcVal v2);

Returns true if the two arguments have the same value. False is returned if the argument are of different types or have different values.

v1ojcVal an object to compare.
v2ojcVal an object to compare.
Returns:the result of the comparison.
ojc_error_str()
const char* ojc_error_str(ojcErrCode code);

Returns a string representation of an error.

codeerror code to return a string for
Returns:string representation of an error code.
ojc_fill()
int ojc_fill(ojcErr err, ojcVal val, int indent, char *buf, size_t len);

Converts val to a JSON formated string in the buffer provided. The indent argument is used indentation of elements in the output.

errpointer to an initialized ojcErr struct.
valojcVal to convert to JSON
indentindentation in spaces to use
bufchar buffer to place the output in
Returns:len size of the buffer.
ojc_fwrite()
int ojc_fwrite(ojcErr err, ojcVal val, int indent, FILE *file);

Converts val to a JSON formated string and streams the output to a file. The indent argument is used indentation of elements in the output.

errpointer to an initialized ojcErr struct.
valojcVal to convert to JSON
indentindentation in spaces to use
filefile to write to
Returns:the number of bytes written.
ojc_get()
ojcVal ojc_get(ojcVal val, const char *path);

Gets an ojcVal located by the provided path where the path is a sequence of keys or indices separated by the / or . character. If the element does not exist a NULL value is returned. A NULL path returns the val argument.

valanchor value for locating the target value
pathlocation of the target value
Returns:the value identified by the path or NULL if it does not exist.
ojc_get_member()
ojcVal ojc_get_member(ojcErr err, ojcVal val, int pos);

Gets a val member in a JSON object at the specified pos. The err struct is set if the object is not an OJCARRAY or OJCOBJECT type. NULL is returned if pos is out of range.

errpointer to an initialized ojcErr struct.
valobject to get the member from
poszero based position of the member to get
ojc_has_key()
bool ojc_has_key(ojcVal val);

Members of a OJC_OBJECT have keys associated with them. This function returns true if the val is a member of an object and thus has a key.

valojcVal to check for a key.
Returns:true if a member of a OJC_OBJECT value and false otherwise.
ojc_int()
int64_t ojc_int(ojcErr err, ojcVal val);

Get the integer value of a ojcVal if it is of type OJC_FIXNUM. If it is not the correct type a type error is returned in the err value.

errstructure to pass the status or an error back in
valojcVal to get the C int64_t from
Returns:the C integer value of the val argument.
ojc_key()
const char* ojc_key(ojcVal val);

If a ojcVal has a key this function returns that key. If it has no key then NULL is returned.

valojcVal to get the key from
Returns:the key associated with the val.
ojc_key_len()
int ojc_key_len(ojcVal val);

valojcVal to get the key length of
Returns:the length of the key
ojc_member_count()
int ojc_member_count(ojcErr err, ojcVal val);

Get number of members of a ojcVal if it is of type OJC_OBJECT or OJC_ARRAY. If it is not the correct type a type error is returned in the err value.

errstructure to pass the status or an error back in
valojcVal to get the members count from
Returns:the number of member values of the val argument.
ojc_members()
ojcVal ojc_members(ojcErr err, ojcVal val);

Get the first child value of a ojcVal if it is of type OJC_OBJECT or OJC_ARRAY. If it is not the correct type a type error is returned in the err value.

errstructure to pass the status or an error back in
valojcVal to get the members of
Returns:the first member value of the val argument.
ojc_merge()
void ojc_merge(ojcErr err, ojcVal primary, ojcVal other);

Merges the other JSON object into the primary JSON object. other values override primary values. Nested values are replaced recursively.

errpointer to an initialized ojcErr struct.
primaryojcVal base object
otherojcVal override object
ojc_next()
ojcVal ojc_next(ojcVal val);

Get the next member value of a ojcVal. NULL is returned if there are not more members.

valojcVal to get the next member from
Returns:the next member value of the val argument.
ojc_number()
const char* ojc_number(ojcErr err, ojcVal val);

Get the number value of a ojcVal if it is of type OJC_NUMBER. If it is not the correct type a type error is returned in the err value.

errstructure to pass the status or an error back in
valojcVal to get the decimal as a string from
Returns:the C string value of the val argument.
ojc_number_len()
int ojc_number_len(ojcErr err, ojcVal val);

Returns the length of the number value.

errstructure to pass the status or an error back in
valojcVal to get the length of the decimal as a string from
zzzzzz
Returns:the length of the numeric as a string.
ojc_object_append()
void ojc_object_append(ojcErr err, ojcVal object, const char *key, ojcVal val);

Appends a val to a JSON object using the specified key. This does not replace previous key-value pairs with the same key value. The err struct is set if the object is not an OJCOBJECT type.

errpointer to an initialized ojcErr struct.
objectobject to append val to
keythe key to use in the key-value pair
valvalue to append
ojc_object_get_by_key()
ojcVal ojc_object_get_by_key(ojcErr err, ojcVal object, const char *key);

Get the first val in a JSON object with the specified key. The err struct is set if the object is not an OJCOBJECT type.

errpointer to an initialized ojcErr struct.
objectobject to get the member from
keythe key to use in finding the key-value pair
ojc_object_insert()
void ojc_object_insert(ojcErr err, ojcVal object, int before, const char *key, ojcVal val);

Inserts a val in a JSON object with the specified key. The insert is before the position specified. The err struct is set if the object is not an OJCOBJECT type.

errpointer to an initialized ojcErr struct.
objectobject to append val to
beforeposition to insert the new value
keythe key to use in the key-value pair
valnew value
ojc_object_nappend()
void ojc_object_append(ojcErr err, ojcVal object, const char *key, ojcVal val);

Appends a val to a JSON object using the specified key. This does not replace previous key-value pairs with the same key value. The err struct is set if the object is not an OJCOBJECT type.

errpointer to an initialized ojcErr struct.
objectobject to append val to
keythe key to use in the key-value pair
valvalue to append
ojc_object_remove_by_key()
bool ojc_object_remove_by_key(ojcErr err, ojcVal object, const char *key);

Removes all members in a JSON object with the specified key. The err struct is set if the object is not an OJCOBJECT type.

errpointer to an initialized ojcErr struct.
objectobject to remove the member from
keythe key to use in the key-value pair
ojc_object_replace()
bool ojc_object_replace(ojcErr err, ojcVal object, const char *key, ojcVal val);

Replaces a val in a JSON object for the specified key. Only the first matching member is replaced. The err struct is set if the object is not an OJCOBJECT type.

errpointer to an initialized ojcErr struct.
objectobject to append val to
keythe key to use in the key-value pair
valnew value
Returns:true if a value was replaced and false if it was appended.
ojc_object_take()
ojcVal ojc_object_take(ojcErr err, ojcVal object, const char *key);

Removes the first member in a JSON object with the specified key. The err struct is set if the object is not an OJCOBJECT type. The removed member is not destroyed.

errpointer to an initialized ojcErr struct.
objectobject to remove the member from
keythe key to use in the key-value pair
ojc_opaque()
void* ojc_opaque(ojcErr err, ojcVal val);

Get the opaque value of a ojcVal if it is of type OJC_OPAQUE. If it is not the correct type a type error is returned in the err value.

errstructure to pass the status or an error back in
valojcVal to get the opaque from
Returns:the C string value of the val argument.
ojc_parse_fd()
ojcVal ojc_parse_fd(ojcErr err, int socket, ojcParseCallback cb, void *ctx);

Parses from a file descriptor or socket. An error will result in the err argument being set with an error code and message. The socket can contain more than one JSON element.

errpointer to an initialized ojcErr struct.
socketsocket to parse
cbcallback function or NULL if no callbacks are desired
ctxcontext for the callback function if provided.
Returns:the parsed JSON as a ojcVal.
ojc_parse_file()
ojcVal ojc_parse_file(ojcErr err, FILE *file, ojcParseCallback cb, void *ctx);

Parses a the contents of a file. An error will result in the err argument being set with an error code and message. The file can contain more than one JSON element.

errpointer to an initialized ojcErr struct.
filefile to parse
cbcallback function or NULL if no callbacks are desired
ctxcontext for the callback function if provided.
Returns:the parsed JSON as a ojcVal.
ojc_parse_file_follow()
void ojc_parse_file_follow(ojcErr err, FILE *file, ojcParseCallback cb, void *ctx);

Parses a the contents of a file without waiting on EOF. This is typically used when tailing a file or redirected input. An error will result in the err argument being set with an error code and message. The file can contain more than one JSON element.

errpointer to an initialized ojcErr struct.
filefile to parse
cbcallback function or NULL if no callbacks are desired
ctxcontext for the callback function if provided.
ojc_parse_reader()
ojcVal ojc_parse_reader(ojcErr err, void *src, ojcReadFunc rf, ojcParseCallback cb, void *ctx);

Parses from the provided src. An error will result in the err argument being set with an error code and message. The socket can contain more than one JSON element. The read function is used with the src to read characters for the parser.

errpointer to an initialized ojcErr struct.
srcsource to extract the json from
rfread function for the src
cbcallback function or NULL if no callbacks are desired
ctxcontext for the callback function if provided.
Returns:the parsed JSON as a ojcVal.
ojc_parse_str()
ojcVal ojc_parse_str(ojcErr err, const char *json, ojcParseCallback cb, void *ctx);

Parses a string. An error will result in the err argument being set with an error code and message. The json string can contain more than one JSON element.

errpointer to an initialized ojcErr struct.
jsonJSON document to parse
cbcallback function or NULL if no callbacks are desired
ctxcontext for the callback function if provided.
Returns:the parsed JSON as a ojcVal.
ojc_parse_strp()
ojcVal ojc_parse_strp(ojcErr err, const char **jsonp);

Parses a string. An error will result in the err argument being set with an error code and message. The function returns after parsing a complete json element. The jsonp will then point to the next character in the original string.

errpointer to an initialized ojcErr struct.
jsonppointer to the JSON document to parse
Returns:the parsed JSON as a ojcVal.
ojc_remove()
bool ojc_remove(ojcErr err, ojcVal anchor, const char *path);

Removes and ojcVal at the provided path where the path is a sequence of keys or indices separated by the / or . character. If any node the call returns false without removing a value.

errpointer to an initialized ojcErr struct.
anchoranchor value for locating the target value
pathlocation of the target value
Returns:true if a value was removed and false if it was not.
ojc_remove_by_pos()
bool ojc_remove_by_pos(ojcErr err, ojcVal object, int pos);

Removes a member in a JSON object at the specified pos. The err struct is set if the object is not an OJCOBJECT type or if there is no member at the position specified.

errpointer to an initialized ojcErr struct.
objectobject to remove the member from
poszero based position of the member to remove
ojc_replace()
bool ojc_replace(ojcErr err, ojcVal anchor, const char *path, ojcVal val);

Replaces or appends an ojcVal at the provided path where the path is a sequence of keys or indices separated by the / or . character. If any node does not exist on the path an Object or Array is created for that element of the path.

errpointer to an initialized ojcErr struct.
anchoranchor value for locating the target value
pathlocation of the target value
valvalue to place at the target location
Returns:true if a value was replaced and false if it was appended.
ojc_set()
bool ojc_set(ojcErr err, ojcVal anchor, const char *path, ojcVal val);

Replaces or appends an ojcVal at the provided path where the path is a sequence of keys or indices separated by the / or . character. If any node does not exist on the path an Object or Array is created for that element of the path.

errpointer to an initialized ojcErr struct.
anchoranchor value for locating the target value
pathlocation of the target value
valvalue to place at the target location
Returns:true if a value was replaced and false if it was appended.
ojc_set_key()
void ojc_set_key(ojcVal val, const char *key);

Sets the ojcVal key.

valojcVal to set the key on.
keyvalue to set as the key
ojc_str()
const char* ojc_str(ojcErr err, ojcVal val);

Get the string value of a ojcVal if it is of type OJC_STRING. If it is not the correct type a type error is returned in the err value.

errstructure to pass the status or an error back in
valojcVal to get the C const char* from
Returns:the C string value of the val argument.
ojc_str_len()
int ojc_str_len(ojcErr err, ojcVal val);

Returns the length of the string value.

errstructure to pass the status or an error back in
valojcVal to get the length of the string from
zzzzzz
Returns:the length of the string.
ojc_to_str()
char* ojc_to_str(ojcVal val, int indent);

Converts val to a JSON formated string. The indent argument is used indentation of elements in the output. The caller is expected to free the returned string.

valojcVal to convert to JSON
indentindentaiton in spaces to use
Returns:JSON string represented by the val.
ojc_type()
ojcValType ojc_type(ojcVal val);

Returns the type of the value.

valvalue to get the type of
Returns:the type of the value.
ojc_type_str()
const char* ojc_type_str(ojcValType type);

Returns a string representation of a type.

typetype to return a string for
Returns:string representation.
ojc_version()
const char* ojc_version();
Returns:version of OjC.
ojc_word()
const char* ojc_word(ojcErr err, ojcVal val);

Get the string value of a ojcVal if it is of type OJC_WORD. If it is not the correct type a type error is returned in the err value.

errstructure to pass the status or an error back in
valojcVal to get the C const char* from
Returns:the C string value of the val argument.
ojc_write()
int ojc_write(ojcErr err, ojcVal val, int indent, int socket);

Converts val to a JSON formated string and streams the output to a file descriptor or socket. The indent argument is used indentation of elements in the output.

errpointer to an initialized ojcErr struct.
valojcVal to convert to JSON
indentindentation in spaces to use
socketsocket to write to