C Server-Side SDK
LaunchDarkly SDK
json.h File Reference

Public API Interface for JSON usage. More...

Include dependency graph for json.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  LDJSONType { LDNull = 0, LDText, LDNumber, LDBool, LDObject, LDArray }
 Represents the type of a LaunchDarkly JSON node. More...
 

Functions

struct LDJSON * LDNewNull (void)
 Constructs a JSON node of type LDJSONNull. More...
 
struct LDJSON * LDNewBool (const LDBoolean boolean)
 Constructs a JSON node of type LDJSONBool. More...
 
struct LDJSON * LDNewNumber (const double number)
 Constructs a JSON node of type LDJSONumber. More...
 
struct LDJSON * LDNewText (const char *const text)
 Returns a new constructed JSON node of type LDJSONText. More...
 
struct LDJSON * LDNewObject (void)
 Constructs a JSON node of type LDJSONObject. More...
 
struct LDJSON * LDNewArray (void)
 Constructs a JSON node of type LDJSONArray. More...
 
LDBoolean LDSetNumber (struct LDJSON *const node, const double number)
 Set the value of an existing Number. More...
 
void LDJSONFree (struct LDJSON *const json)
 Frees any allocated JSON structure. More...
 
struct LDJSON * LDJSONDuplicate (const struct LDJSON *const json)
 Duplicates an existing JSON strucutre. This acts as a deep copy. More...
 
LDJSONType LDJSONGetType (const struct LDJSON *const json)
 Get the type of a JSON structure. More...
 
LDBoolean LDJSONCompare (const struct LDJSON *const left, const struct LDJSON *const right)
 Deep compare to check if two JSON structures are equal. More...
 
LDBoolean LDGetBool (const struct LDJSON *const node)
 Get the value from a node of type LDJSONBool. More...
 
double LDGetNumber (const struct LDJSON *const node)
 Get the value from a node of type LDJSONNumber. More...
 
const char * LDGetText (const struct LDJSON *const node)
 Get the value from a node of type LDJSONText. More...
 
struct LDJSON * LDIterNext (const struct LDJSON *const iter)
 Returns the next item in the sequence. More...
 
struct LDJSON * LDGetIter (const struct LDJSON *const collection)
 Allows iteration over an array. Modification of the array invalidates this iterator. More...
 
const char * LDIterKey (const struct LDJSON *const iter)
 Returns the key associated with the iterator Must be an object iterator. More...
 
unsigned int LDCollectionGetSize (const struct LDJSON *const collection)
 Return the size of a JSON collection. More...
 
struct LDJSON * LDCollectionDetachIter (struct LDJSON *const collection, struct LDJSON *const iter)
 Remove an iterator from a collection. More...
 
struct LDJSON * LDArrayLookup (const struct LDJSON *const array, const unsigned int index)
 Lookup up the value of an index for a given array. More...
 
LDBoolean LDArrayPush (struct LDJSON *const array, struct LDJSON *const item)
 Adds an item to the end of an existing array. More...
 
LDBoolean LDArrayAppend (struct LDJSON *const prefix, const struct LDJSON *const suffix)
 Appends the array on the right to the array on the left. More...
 
struct LDJSON * LDObjectLookup (const struct LDJSON *const object, const char *const key)
 Lookup up the value of a key for a given object. More...
 
LDBoolean LDObjectSetKey (struct LDJSON *const object, const char *const key, struct LDJSON *const item)
 Sets the provided key in an object to item. If the key already exists the original value is deleted. More...
 
void LDObjectDeleteKey (struct LDJSON *const object, const char *const key)
 Delete the provided key from the given object. More...
 
struct LDJSON * LDObjectDetachKey (struct LDJSON *const object, const char *const key)
 Detach the provided key from the given object. The returned value is no longer owned by the object and must be manually deleted. More...
 
LDBoolean LDObjectMerge (struct LDJSON *const to, const struct LDJSON *const from)
 Copy keys from one object to another. If a key already exists it is overwritten by the new value. More...
 
char * LDJSONSerialize (const struct LDJSON *const json)
 Serialize JSON structure into JSON text. More...
 
struct LDJSON * LDJSONDeserialize (const char *const text)
 Deserialize JSON text into a JSON structure. More...
 

Detailed Description

Public API Interface for JSON usage.

Enumeration Type Documentation

◆ LDJSONType

enum LDJSONType

Represents the type of a LaunchDarkly JSON node.

Enumerator
LDNull 

JSON Null (not JSON undefined)

LDText 

UTF-8 JSON string.

LDNumber 

JSON number (Double or Integer)

LDBool 

JSON boolean (True or False)

LDObject 

JSON string indexed map.

LDArray 

JSON integer indexed array.

Function Documentation

◆ LDArrayAppend()

LDBoolean LDArrayAppend ( struct LDJSON *const  prefix,
const struct LDJSON *const  suffix 
)

Appends the array on the right to the array on the left.

Parameters
[in]prefixMust be of type LDJSONArray.
[in]suffixMust be of type LDJSONArray.
Returns
True on success, False on failure.

◆ LDArrayLookup()

struct LDJSON* LDArrayLookup ( const struct LDJSON *const  array,
const unsigned int  index 
)

Lookup up the value of an index for a given array.

Parameters
[in]arrayMay not be NULL. must be of type LDJSONArray.
[in]indexThe index to lookup in the array
Returns
Item if it exists, otherwise NULL if does not exist, or on failure.

◆ LDArrayPush()

LDBoolean LDArrayPush ( struct LDJSON *const  array,
struct LDJSON *const  item 
)

Adds an item to the end of an existing array.

Parameters
[in]arrayMust be of type LDJSONArray.
[in]itemThe value to append to the array. This item is consumed.
Returns
True on success, False on failure.

◆ LDCollectionDetachIter()

struct LDJSON* LDCollectionDetachIter ( struct LDJSON *const  collection,
struct LDJSON *const  iter 
)

Remove an iterator from a collection.

Parameters
[in]collectionMay not be NULL. must be of type LDJSONArray or LDJSONObject.
[in]iterMay not be NULL.
Returns
The detached iterator, or NULL on failure.

◆ LDCollectionGetSize()

unsigned int LDCollectionGetSize ( const struct LDJSON *const  collection)

Return the size of a JSON collection.

Parameters
[in]collectionMay not be NULL. must be of type LDJSONArray or LDJSONObject.
Returns
The size of the collection, or zero on failure.

◆ LDGetBool()

LDBoolean LDGetBool ( const struct LDJSON *const  node)

Get the value from a node of type LDJSONBool.

Parameters
[in]nodeNode to read value from. Must be correct type.
Returns
The boolean nodes value. Returns false on failure.

◆ LDGetIter()

struct LDJSON* LDGetIter ( const struct LDJSON *const  collection)

Allows iteration over an array. Modification of the array invalidates this iterator.

Parameters
[in]collectionMay not be NULL. must be of type LDJSONArray or LDJSONObject.
Returns
First child iterator, or NULL if empty or on failure.

◆ LDGetNumber()

double LDGetNumber ( const struct LDJSON *const  node)

Get the value from a node of type LDJSONNumber.

Parameters
[in]nodeNode to read value from. Must be correct type.
Returns
The number nodes value. Returns 0 on failure.

◆ LDGetText()

const char* LDGetText ( const struct LDJSON *const  node)

Get the value from a node of type LDJSONText.

Parameters
[in]nodeNode to read value from. Must be correct type.
Returns
The text nodes value. NULL on failure.

◆ LDIterKey()

const char* LDIterKey ( const struct LDJSON *const  iter)

Returns the key associated with the iterator Must be an object iterator.

Parameters
[in]iterThe iterator obtained from an object. May not be NULL.
Returns
The key on success, or NULL if there is no key, or on failure.

◆ LDIterNext()

struct LDJSON* LDIterNext ( const struct LDJSON *const  iter)

Returns the next item in the sequence.

Parameters
[in]iterMay be not be NULL (assert)
Returns
Item, or NULL if the iterator is finished.

◆ LDJSONCompare()

LDBoolean LDJSONCompare ( const struct LDJSON *const  left,
const struct LDJSON *const  right 
)

Deep compare to check if two JSON structures are equal.

Parameters
[in]leftMay be NULL.
[in]rightMay be NULL.
Returns
True if equal, false otherwise.

◆ LDJSONDeserialize()

struct LDJSON* LDJSONDeserialize ( const char *const  text)

Deserialize JSON text into a JSON structure.

Parameters
[in]textJSON text to deserialize. May not be NULL.
Returns
JSON structure on success, NULL on failure.

◆ LDJSONDuplicate()

struct LDJSON* LDJSONDuplicate ( const struct LDJSON *const  json)

Duplicates an existing JSON strucutre. This acts as a deep copy.

Parameters
[in]jsonJSON to be duplicated. May not be NULL.
Returns
NULL on failure

◆ LDJSONFree()

void LDJSONFree ( struct LDJSON *const  json)

Frees any allocated JSON structure.

Parameters
[in]jsonMay be NULL.
Returns
Void.

◆ LDJSONGetType()

LDJSONType LDJSONGetType ( const struct LDJSON *const  json)

Get the type of a JSON structure.

Parameters
[in]jsonMay be not be NULL.
Returns
The JSON type, or LDNull on failure.

◆ LDJSONSerialize()

char* LDJSONSerialize ( const struct LDJSON *const  json)

Serialize JSON structure into JSON text.

Parameters
[in]jsonStructure to serialize. May be NULL.
Returns
NULL on failure

◆ LDNewArray()

struct LDJSON* LDNewArray ( void  )

Constructs a JSON node of type LDJSONArray.

Returns
NULL on failure.

◆ LDNewBool()

struct LDJSON* LDNewBool ( const LDBoolean  boolean)

Constructs a JSON node of type LDJSONBool.

Parameters
[in]booleanThe value to assign the new node
Returns
NULL on failure.

◆ LDNewNull()

struct LDJSON* LDNewNull ( void  )

Constructs a JSON node of type LDJSONNull.

Returns
NULL on failure.

◆ LDNewNumber()

struct LDJSON* LDNewNumber ( const double  number)

Constructs a JSON node of type LDJSONumber.

Parameters
[in]numberThe value to assign the new node
Returns
NULL on failure.

◆ LDNewObject()

struct LDJSON* LDNewObject ( void  )

Constructs a JSON node of type LDJSONObject.

Returns
NULL on failure.

◆ LDNewText()

struct LDJSON* LDNewText ( const char *const  text)

Returns a new constructed JSON node of type LDJSONText.

Parameters
[in]textThe text to copy and then assign the new node. May not be NULL.
Returns
NULL on failure.

◆ LDObjectDeleteKey()

void LDObjectDeleteKey ( struct LDJSON *const  object,
const char *const  key 
)

Delete the provided key from the given object.

Parameters
[in]objectMay not be NULL. must be of type LDJSONObject.
[in]keyThe key to delete from the object. May not be NULL.
Returns
Void

◆ LDObjectDetachKey()

struct LDJSON* LDObjectDetachKey ( struct LDJSON *const  object,
const char *const  key 
)

Detach the provided key from the given object. The returned value is no longer owned by the object and must be manually deleted.

Parameters
[in]objectMay not be NULL. must be of type LDJSONObject.
[in]keyThe key to detach from the object. May not be NULL.
Returns
The value associated, or NULL if it does not exit, or on error.

◆ LDObjectLookup()

struct LDJSON* LDObjectLookup ( const struct LDJSON *const  object,
const char *const  key 
)

Lookup up the value of a key for a given object.

Parameters
[in]objectMay not be NULL. must be of type LDJSONObject.
[in]keyThe key to lookup in the object. May not be NULL.
Returns
The item if it exists, otherwise NULL.

◆ LDObjectMerge()

LDBoolean LDObjectMerge ( struct LDJSON *const  to,
const struct LDJSON *const  from 
)

Copy keys from one object to another. If a key already exists it is overwritten by the new value.

Parameters
[in]toObject to assign to. May not be NULL.
[in]fromObject to copy keys from. May not be NULL.
Returns
True on success, to is polluted on failure.

◆ LDObjectSetKey()

LDBoolean LDObjectSetKey ( struct LDJSON *const  object,
const char *const  key,
struct LDJSON *const  item 
)

Sets the provided key in an object to item. If the key already exists the original value is deleted.

Parameters
[in]objectMust be of type LDJSONObject.
[in]keyThe key that is being written to in the object. May not be NULL.
[in]itemThe value to assign to key. This item is consumed.
Returns
True on success, False on failure.

◆ LDSetNumber()

LDBoolean LDSetNumber ( struct LDJSON *const  node,
const double  number 
)

Set the value of an existing Number.

Parameters
[in]nodeThe node to set the value of. Must be a number.
[in]numberThe value to use for the node.
Returns
True on success, False on failure.