C Server-Side SDK
LaunchDarkly SDK
json.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <launchdarkly/boolean.h>
9 #include <launchdarkly/export.h>
10 
11 /* **** Forward Declarations **** */
12 
13 struct LDJSON;
14 
16 typedef enum
17 {
19  LDNull = 0,
30 } LDJSONType;
31 
32 /*******************************************************************************
33  * @name Constructing values
34  * Routines for constructing values
35  * @{
36  ******************************************************************************/
37 
42 LD_EXPORT(struct LDJSON *) LDNewNull(void);
43 
49 LD_EXPORT(struct LDJSON *) LDNewBool(const LDBoolean boolean);
50 
56 LD_EXPORT(struct LDJSON *) LDNewNumber(const double number);
57 
64 LD_EXPORT(struct LDJSON *) LDNewText(const char *const text);
65 
70 LD_EXPORT(struct LDJSON *) LDNewObject(void);
71 
76 LD_EXPORT(struct LDJSON *) LDNewArray(void);
77 
80 /*******************************************************************************
81  * @name Setting values
82  * Routines for setting values of existing nodes
83  * @{
84  ******************************************************************************/
85 
92 LD_EXPORT(LDBoolean)
93 LDSetNumber(struct LDJSON *const node, const double number);
94 
97 /*******************************************************************************
98  * @name Cleanup and Utility
99  * Miscellaneous Operations
100  * @{
101  *******************************************************************************/
102 
108 LD_EXPORT(void) LDJSONFree(struct LDJSON *const json);
109 
115 LD_EXPORT(struct LDJSON *) LDJSONDuplicate(const struct LDJSON *const json);
116 
122 LD_EXPORT(LDJSONType) LDJSONGetType(const struct LDJSON *const json);
123 
130 LD_EXPORT(LDBoolean)
132  const struct LDJSON *const left, const struct LDJSON *const right);
133 
136 /*******************************************************************************
137  * @name Reading Values
138  * Routines for reading values
139  * @{
140  ******************************************************************************/
141 
147 LD_EXPORT(LDBoolean) LDGetBool(const struct LDJSON *const node);
148 
154 LD_EXPORT(double) LDGetNumber(const struct LDJSON *const node);
155 
161 LD_EXPORT(const char *) LDGetText(const struct LDJSON *const node);
162 
165 /*******************************************************************************
166  * @name Iterator Operations
167  * Routines for working with collections (Objects, Arrays)
168  * @{
169  ******************************************************************************/
170 
176 LD_EXPORT(struct LDJSON *) LDIterNext(const struct LDJSON *const iter);
177 
185 LD_EXPORT(struct LDJSON *) LDGetIter(const struct LDJSON *const collection);
186 
194 LD_EXPORT(const char *) LDIterKey(const struct LDJSON *const iter);
195 
202 LD_EXPORT(unsigned int)
203 LDCollectionGetSize(const struct LDJSON *const collection);
204 
212 LD_EXPORT(struct LDJSON *)
214  struct LDJSON *const collection, struct LDJSON *const iter);
215 
218 /*******************************************************************************
219  * @name Array Operations
220  * Routines for working with arrays
221  * @{
222  ******************************************************************************/
223 
231 LD_EXPORT(struct LDJSON *)
232 LDArrayLookup(const struct LDJSON *const array, const unsigned int index);
233 
240 LD_EXPORT(LDBoolean)
241 LDArrayPush(struct LDJSON *const array, struct LDJSON *const item);
242 
249 LD_EXPORT(LDBoolean)
250 LDArrayAppend(struct LDJSON *const prefix, const struct LDJSON *const suffix);
251 
252 /*******************************************************************************
253  * @name Object Operations
254  * Routines for working with objects
255  * @{
256  ******************************************************************************/
257 
265 LD_EXPORT(struct LDJSON *)
266 LDObjectLookup(const struct LDJSON *const object, const char *const key);
267 
277 LD_EXPORT(LDBoolean)
279  struct LDJSON *const object,
280  const char *const key,
281  struct LDJSON *const item);
282 
290 LD_EXPORT(void)
291 LDObjectDeleteKey(struct LDJSON *const object, const char *const key);
292 
301 LD_EXPORT(struct LDJSON *)
302 LDObjectDetachKey(struct LDJSON *const object, const char *const key);
303 
311 LD_EXPORT(LDBoolean)
312 LDObjectMerge(struct LDJSON *const to, const struct LDJSON *const from);
313 
316 /*******************************************************************************
317  * @name Serialization / Deserialization
318  * Working with textual representations of JSON
319  * @{
320  ******************************************************************************/
321 
328 LD_EXPORT(char *) LDJSONSerialize(const struct LDJSON *const json);
329 
335 LD_EXPORT(struct LDJSON *) LDJSONDeserialize(const char *const text);
336 
LDNull
@ LDNull
JSON Null (not JSON undefined)
Definition: json.h:19
LDJSONCompare
LDBoolean LDJSONCompare(const struct LDJSON *const left, const struct LDJSON *const right)
Deep compare to check if two JSON structures are equal.
LDNewNull
struct LDJSON * LDNewNull(void)
Constructs a JSON node of type LDJSONNull.
boolean.h
A custom c89 boolean type.
LDCollectionDetachIter
struct LDJSON * LDCollectionDetachIter(struct LDJSON *const collection, struct LDJSON *const iter)
Remove an iterator from a collection.
LDJSONType
LDJSONType
Represents the type of a LaunchDarkly JSON node.
Definition: json.h:16
LDGetBool
LDBoolean LDGetBool(const struct LDJSON *const node)
Get the value from a node of type LDJSONBool.
LDGetText
const char * LDGetText(const struct LDJSON *const node)
Get the value from a node of type LDJSONText.
LDSetNumber
LDBoolean LDSetNumber(struct LDJSON *const node, const double number)
Set the value of an existing Number.
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 an...
LDArrayLookup
struct LDJSON * LDArrayLookup(const struct LDJSON *const array, const unsigned int index)
Lookup up the value of an index for a given array.
LDJSONDuplicate
struct LDJSON * LDJSONDuplicate(const struct LDJSON *const json)
Duplicates an existing JSON structure. This acts as a deep copy.
LDJSONGetType
LDJSONType LDJSONGetType(const struct LDJSON *const json)
Get the type of a JSON structure.
LD_EXPORT
#define LD_EXPORT(x)
Used to ensure only intended symbols are exported in the binaries.
Definition: export.h:10
LDNewNumber
struct LDJSON * LDNewNumber(const double number)
Constructs a JSON node of type LDJSONumber.
LDArray
@ LDArray
JSON integer indexed array.
Definition: json.h:29
LDText
@ LDText
UTF-8 JSON string.
Definition: json.h:21
LDGetNumber
double LDGetNumber(const struct LDJSON *const node)
Get the value from a node of type LDJSONNumber.
LDNewText
struct LDJSON * LDNewText(const char *const text)
Returns a new constructed JSON node of type LDJSONText.
LDNewBool
struct LDJSON * LDNewBool(const LDBoolean boolean)
Constructs a JSON node of type LDJSONBool.
LDBool
@ LDBool
JSON boolean (True or False)
Definition: json.h:25
LDJSONDeserialize
struct LDJSON * LDJSONDeserialize(const char *const text)
Deserialize JSON text into a JSON structure.
LDArrayPush
LDBoolean LDArrayPush(struct LDJSON *const array, struct LDJSON *const item)
Adds an item to the end of an existing array.
LDNewArray
struct LDJSON * LDNewArray(void)
Constructs a JSON node of type LDJSONArray.
LDCollectionGetSize
unsigned int LDCollectionGetSize(const struct LDJSON *const collection)
Return the size of a JSON collection.
LDObjectDeleteKey
void LDObjectDeleteKey(struct LDJSON *const object, const char *const key)
Delete the provided key from the given object.
LDJSONSerialize
char * LDJSONSerialize(const struct LDJSON *const json)
Serialize JSON structure into JSON text.
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.
LDJSONFree
void LDJSONFree(struct LDJSON *const json)
Frees any allocated JSON structure.
LDIterNext
struct LDJSON * LDIterNext(const struct LDJSON *const iter)
Returns the next item in the sequence.
LDNewObject
struct LDJSON * LDNewObject(void)
Constructs a JSON node of type LDJSONObject.
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.
LDIterKey
const char * LDIterKey(const struct LDJSON *const iter)
Returns the key associated with the iterator Must be an object iterator.
LDObject
@ LDObject
JSON string indexed map.
Definition: json.h:27
LDArrayAppend
LDBoolean LDArrayAppend(struct LDJSON *const prefix, const struct LDJSON *const suffix)
Appends the array on the right to the array on the left.
LDGetIter
struct LDJSON * LDGetIter(const struct LDJSON *const collection)
Allows iteration over an array. Modification of the array invalidates this iterator.
LDObjectLookup
struct LDJSON * LDObjectLookup(const struct LDJSON *const object, const char *const key)
Lookup up the value of a key for a given object.
LDNumber
@ LDNumber
JSON number (Double or Integer)
Definition: json.h:23
export.h
Public. Configuration of exported symbols.