cfengine  3.15.4
About: CFEngine is a configuration management system for configuring and maintaining Unix-like computers (using an own high level policy language). Community version.
  Fossies Dox: cfengine-3.15.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

json.h File Reference
#include <writer.h>
#include <inttypes.h>
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.

Data Structures

struct  JsonIterator
 
struct  _Slice
 

Typedefs

typedef struct JsonElement_ JsonElement
 
typedef struct _Slice Slice
 
typedef int JsonComparator(const JsonElement *, const JsonElement *, void *user_data)
 
typedef JsonElementJsonLookup(void *ctx, const char **data)
 

Enumerations

enum  JsonElementType { JSON_ELEMENT_TYPE_CONTAINER = 1 , JSON_ELEMENT_TYPE_PRIMITIVE = 2 }
 JSON data-structure. More...
 
enum  JsonContainerType { JSON_CONTAINER_TYPE_OBJECT = 3 , JSON_CONTAINER_TYPE_ARRAY = 4 }
 
enum  JsonPrimitiveType {
  JSON_PRIMITIVE_TYPE_STRING = 5 , JSON_PRIMITIVE_TYPE_INTEGER = 6 , JSON_PRIMITIVE_TYPE_REAL = 7 , JSON_PRIMITIVE_TYPE_BOOL = 8 ,
  JSON_PRIMITIVE_TYPE_NULL = 9
}
 
enum  JsonType {
  JSON_TYPE_OBJECT = JSON_CONTAINER_TYPE_OBJECT , JSON_TYPE_ARRAY = JSON_CONTAINER_TYPE_ARRAY , JSON_TYPE_STRING = JSON_PRIMITIVE_TYPE_STRING , JSON_TYPE_INTEGER = JSON_PRIMITIVE_TYPE_INTEGER ,
  JSON_TYPE_REAL = JSON_PRIMITIVE_TYPE_REAL , JSON_TYPE_BOOL = JSON_PRIMITIVE_TYPE_BOOL , JSON_TYPE_NULL = JSON_PRIMITIVE_TYPE_NULL
}
 
enum  JsonParseError {
  JSON_PARSE_OK = 0 , JSON_PARSE_ERROR_STRING_NO_DOUBLEQUOTE_START , JSON_PARSE_ERROR_STRING_NO_DOUBLEQUOTE_END , JSON_PARSE_ERROR_NUMBER_EXPONENT_NEGATIVE ,
  JSON_PARSE_ERROR_NUMBER_EXPONENT_POSITIVE , JSON_PARSE_ERROR_NUMBER_DUPLICATE_ZERO , JSON_PARSE_ERROR_NUMBER_NO_DIGIT , JSON_PARSE_ERROR_NUMBER_MULTIPLE_DOTS ,
  JSON_PARSE_ERROR_NUMBER_EXPONENT_DUPLICATE , JSON_PARSE_ERROR_NUMBER_EXPONENT_DIGIT , JSON_PARSE_ERROR_NUMBER_EXPONENT_FOLLOW_LEADING_ZERO , JSON_PARSE_ERROR_NUMBER_BAD_SYMBOL ,
  JSON_PARSE_ERROR_NUMBER_DIGIT_END , JSON_PARSE_ERROR_ARRAY_START , JSON_PARSE_ERROR_ARRAY_END , JSON_PARSE_ERROR_ARRAY_COMMA ,
  JSON_PARSE_ERROR_OBJECT_BAD_SYMBOL , JSON_PARSE_ERROR_OBJECT_START , JSON_PARSE_ERROR_OBJECT_END , JSON_PARSE_ERROR_OBJECT_COLON ,
  JSON_PARSE_ERROR_OBJECT_COMMA , JSON_PARSE_ERROR_OBJECT_ARRAY_LVAL , JSON_PARSE_ERROR_OBJECT_OBJECT_LVAL , JSON_PARSE_ERROR_OBJECT_OPEN_LVAL ,
  JSON_PARSE_ERROR_INVALID_START , JSON_PARSE_ERROR_NO_LIBYAML , JSON_PARSE_ERROR_LIBYAML_FAILURE , JSON_PARSE_ERROR_NO_SUCH_FILE ,
  JSON_PARSE_ERROR_NO_DATA , JSON_PARSE_ERROR_TRUNCATED , JSON_PARSE_ERROR_MAX
}
 

Functions

char * JsonDecodeString (const char *escaped_string)
 
char * JsonEncodeString (const char *const unescaped_string)
 
char * Json5EscapeData (Slice unescaped_data)
 
JsonElementJsonCopy (const JsonElement *json)
 
int JsonCompare (const JsonElement *a, const JsonElement *b)
 
JsonElementJsonMerge (const JsonElement *a, const JsonElement *b)
 
void JsonDestroy (JsonElement *element)
 Destroy a JSON element. More...
 
void JsonDestroyMaybe (JsonElement *element, bool allocated)
 Destroy a JSON element if needed. More...
 
size_t JsonLength (const JsonElement *element)
 Get the length of a JsonElement. This is the number of elements or fields in an array or object respectively. More...
 
JsonElementType JsonGetElementType (const JsonElement *element)
 
JsonType JsonGetType (const JsonElement *element)
 
const char * JsonElementGetPropertyName (const JsonElement *element)
 
const char * JsonGetPropertyAsString (const JsonElement *element)
 
const char * JsonPrimitiveTypeToString (JsonPrimitiveType type)
 
JsonPrimitiveType JsonGetPrimitiveType (const JsonElement *primitive)
 
const char * JsonPrimitiveGetAsString (const JsonElement *primitive)
 
char * JsonPrimitiveToString (const JsonElement *primitive)
 
bool JsonPrimitiveGetAsBool (const JsonElement *primitive)
 
long JsonPrimitiveGetAsInteger (const JsonElement *primitive)
 
int JsonPrimitiveGetAsInt64 (const JsonElement *primitive, int64_t *value_out)
 
int64_t JsonPrimitiveGetAsInt64DefaultOnError (const JsonElement *primitive, int64_t default_return)
 
int64_t JsonPrimitiveGetAsInt64ExitOnError (const JsonElement *primitive)
 
double JsonPrimitiveGetAsReal (const JsonElement *primitive)
 
JsonElementJsonStringCreate (const char *value)
 
JsonElementJsonIntegerCreate (int value)
 
JsonElementJsonRealCreate (double value)
 
JsonElementJsonBoolCreate (bool value)
 
JsonElementJsonNullCreate ()
 
void JsonContainerReverse (JsonElement *array)
 
void JsonSort (const JsonElement *container, JsonComparator *Compare, void *user_data)
 
JsonElementJsonAt (const JsonElement *container, size_t index)
 
JsonElementJsonSelect (JsonElement *element, size_t num_indices, char **indices)
 
JsonContainerType JsonGetContainerType (const JsonElement *container)
 
JsonElementJsonObjectCreate (size_t initial_capacity)
 Create a new JSON object. More...
 
void JsonObjectAppendString (JsonElement *object, const char *key, const char *value)
 Append a string field to an object. More...
 
void JsonObjectAppendInteger (JsonElement *object, const char *key, int value)
 Append an integer field to an object. More...
 
void JsonObjectAppendReal (JsonElement *object, const char *key, double value)
 Append an real number field to an object. More...
 
void JsonObjectAppendBool (JsonElement *object, const char *key, _Bool value)
 
void JsonObjectAppendNull (JsonElement *object, const char *key)
 Append null field to an object. More...
 
void JsonObjectAppendArray (JsonElement *object, const char *key, JsonElement *array)
 Append an array field to an object. More...
 
void JsonObjectAppendObject (JsonElement *object, const char *key, JsonElement *childObject)
 Append an object field to an object. More...
 
void JsonObjectAppendElement (JsonElement *object, const char *key, JsonElement *element)
 Append any JSON element to an object. More...
 
const char * JsonObjectGetAsString (const JsonElement *object, const char *key)
 Get the value of a field in an object, as a string. More...
 
JsonElementJsonObjectGetAsObject (JsonElement *object, const char *key)
 Get the value of a field in an object, as an object. More...
 
JsonElementJsonObjectGetAsArray (JsonElement *object, const char *key)
 Get the value of a field in an object, as an array. More...
 
JsonElementJsonObjectGet (const JsonElement *object, const char *key)
 
bool JsonObjectRemoveKey (JsonElement *object, const char *key)
 Remove key from the object. More...
 
JsonElementJsonObjectDetachKey (JsonElement *object, const char *key)
 Detach json element ownership from parent object;. More...
 
JsonElementJsonArrayCreate (size_t initialCapacity)
 Create a new JSON array. More...
 
void JsonArrayAppendString (JsonElement *array, const char *value)
 Append a string to an array. More...
 
void JsonArrayAppendBool (JsonElement *array, bool value)
 
void JsonArrayAppendInteger (JsonElement *array, int value)
 Append an integer to an array. More...
 
void JsonArrayAppendReal (JsonElement *array, double value)
 Append an real to an array. More...
 
void JsonArrayAppendNull (JsonElement *array)
 Append null to an array. More...
 
void JsonArrayAppendArray (JsonElement *array, JsonElement *child_array)
 Append an array to an array. More...
 
void JsonArrayAppendObject (JsonElement *array, JsonElement *object)
 Append an object to an array. More...
 
void JsonArrayAppendElement (JsonElement *array, JsonElement *element)
 Append any JSON element to an array. More...
 
void JsonArrayRemoveRange (JsonElement *array, size_t start, size_t end)
 Remove an inclusive range from a JSON array. More...
 
const char * JsonArrayGetAsString (JsonElement *array, size_t index)
 Get a string value from an array. More...
 
JsonElementJsonArrayGetAsObject (JsonElement *array, size_t index)
 Get an object value from an array. More...
 
JsonElementJsonArrayGet (const JsonElement *array, size_t index)
 
bool JsonArrayContainsOnlyPrimitives (JsonElement *array)
 Check if an array contains only primitives. More...
 
JsonIterator JsonIteratorInit (const JsonElement *container)
 
const char * JsonIteratorNextKey (JsonIterator *iter)
 
JsonElementJsonIteratorNextValue (JsonIterator *iter)
 
JsonElementJsonIteratorNextValueByType (JsonIterator *iter, JsonElementType type, bool skip_null)
 
const char * JsonIteratorCurrentKey (const JsonIterator *iter)
 
JsonElementJsonIteratorCurrentValue (const JsonIterator *iter)
 
JsonElementType JsonIteratorCurrentElementType (const JsonIterator *iter)
 
JsonContainerType JsonIteratorCurrentContainerType (const JsonIterator *iter)
 
JsonPrimitiveType JsonIteratorCurrentPrimitiveType (const JsonIterator *iter)
 
bool JsonIteratorHasMore (const JsonIterator *iter)
 
JsonParseError JsonParse (const char **data, JsonElement **json_out)
 Parse a string to create a JsonElement. More...
 
JsonParseError JsonParseWithLookup (void *lookup_data, JsonLookup *lookup_function, const char **data, JsonElement **json_out)
 Parse a string to create a JsonElement. More...
 
JsonParseError JsonParseAnyFile (const char *path, size_t size_max, JsonElement **json_out, bool yaml_format)
 Convenience function to parse JSON or YAML from a file. More...
 
JsonParseError JsonParseFile (const char *path, size_t size_max, JsonElement **json_out)
 Convenience function to parse JSON from a file. More...
 
const char * JsonParseErrorToString (JsonParseError error)
 
void JsonWrite (Writer *writer, const JsonElement *element, size_t indent_level)
 Pretty-print a JsonElement recursively into a Writer. If it's a JsonObject, its children will be sorted to produce canonical JSON output, but the object's contents are not modified so it's still a const. More...
 
void JsonWriteCompact (Writer *w, const JsonElement *element)
 

Typedef Documentation

◆ JsonComparator

typedef int JsonComparator(const JsonElement *, const JsonElement *, void *user_data)

Definition at line 218 of file json.h.

◆ JsonElement

typedef struct JsonElement_ JsonElement

Definition at line 1 of file json.h.

◆ JsonLookup

typedef JsonElement* JsonLookup(void *ctx, const char **data)

Definition at line 466 of file json.h.

◆ Slice

typedef struct _Slice Slice

Enumeration Type Documentation

◆ JsonContainerType

Enumerator
JSON_CONTAINER_TYPE_OBJECT 
JSON_CONTAINER_TYPE_ARRAY 

Definition at line 56 of file json.h.

◆ JsonElementType

JSON data-structure.

This is a JSON Document Object Model (DOM). Clients deal only with the opaque JsonElement, which may be either a container or a primitive (client should probably not deal much with primitive elements). A JSON container may be either an object or an array. The JSON DOM currently supports copy semantics for primitive values, but not for container types. In practice, this means that clients always just free the parent element, but an element should just have a single parent, or none.

JSON primitives as JsonElement are currently not well supported.

JSON DOM is currently built upon Sequence. The JSON specification may be found at http://www.json.org.

See also
Sequence
Enumerator
JSON_ELEMENT_TYPE_CONTAINER 
JSON_ELEMENT_TYPE_PRIMITIVE 

Definition at line 50 of file json.h.

◆ JsonParseError

Enumerator
JSON_PARSE_OK 
JSON_PARSE_ERROR_STRING_NO_DOUBLEQUOTE_START 
JSON_PARSE_ERROR_STRING_NO_DOUBLEQUOTE_END 
JSON_PARSE_ERROR_NUMBER_EXPONENT_NEGATIVE 
JSON_PARSE_ERROR_NUMBER_EXPONENT_POSITIVE 
JSON_PARSE_ERROR_NUMBER_DUPLICATE_ZERO 
JSON_PARSE_ERROR_NUMBER_NO_DIGIT 
JSON_PARSE_ERROR_NUMBER_MULTIPLE_DOTS 
JSON_PARSE_ERROR_NUMBER_EXPONENT_DUPLICATE 
JSON_PARSE_ERROR_NUMBER_EXPONENT_DIGIT 
JSON_PARSE_ERROR_NUMBER_EXPONENT_FOLLOW_LEADING_ZERO 
JSON_PARSE_ERROR_NUMBER_BAD_SYMBOL 
JSON_PARSE_ERROR_NUMBER_DIGIT_END 
JSON_PARSE_ERROR_ARRAY_START 
JSON_PARSE_ERROR_ARRAY_END 
JSON_PARSE_ERROR_ARRAY_COMMA 
JSON_PARSE_ERROR_OBJECT_BAD_SYMBOL 
JSON_PARSE_ERROR_OBJECT_START 
JSON_PARSE_ERROR_OBJECT_END 
JSON_PARSE_ERROR_OBJECT_COLON 
JSON_PARSE_ERROR_OBJECT_COMMA 
JSON_PARSE_ERROR_OBJECT_ARRAY_LVAL 
JSON_PARSE_ERROR_OBJECT_OBJECT_LVAL 
JSON_PARSE_ERROR_OBJECT_OPEN_LVAL 
JSON_PARSE_ERROR_INVALID_START 
JSON_PARSE_ERROR_NO_LIBYAML 
JSON_PARSE_ERROR_LIBYAML_FAILURE 
JSON_PARSE_ERROR_NO_SUCH_FILE 
JSON_PARSE_ERROR_NO_DATA 
JSON_PARSE_ERROR_TRUNCATED 
JSON_PARSE_ERROR_MAX 

Definition at line 82 of file json.h.

◆ JsonPrimitiveType

Enumerator
JSON_PRIMITIVE_TYPE_STRING 
JSON_PRIMITIVE_TYPE_INTEGER 
JSON_PRIMITIVE_TYPE_REAL 
JSON_PRIMITIVE_TYPE_BOOL 
JSON_PRIMITIVE_TYPE_NULL 

Definition at line 62 of file json.h.

◆ JsonType

enum JsonType
Enumerator
JSON_TYPE_OBJECT 
JSON_TYPE_ARRAY 
JSON_TYPE_STRING 
JSON_TYPE_INTEGER 
JSON_TYPE_REAL 
JSON_TYPE_BOOL 
JSON_TYPE_NULL 

Definition at line 71 of file json.h.

Function Documentation

◆ Json5EscapeData()

char* Json5EscapeData ( Slice  unescaped_data)

Definition at line 1046 of file json.c.

References Json5EscapeDataWriter(), StringWriter(), and StringWriterClose().

◆ JsonArrayAppendArray()

void JsonArrayAppendArray ( JsonElement array,
JsonElement child_array 
)

Append an array to an array.

Parameters
array[in] The JSON array parent.
child_array[in] The array value to append.

Definition at line 1317 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_ARRAY, JSON_ELEMENT_TYPE_CONTAINER, JsonArrayAppendElement(), NULL, and JsonElement_::type.

Referenced by BuildData(), JsonParseAsArray(), JsonParseCsvFile(), and RlistToJson().

◆ JsonArrayAppendBool()

void JsonArrayAppendBool ( JsonElement array,
bool  value 
)

Definition at line 1293 of file json.c.

References JsonArrayAppendElement(), and JsonBoolCreate().

◆ JsonArrayAppendElement()

◆ JsonArrayAppendInteger()

void JsonArrayAppendInteger ( JsonElement array,
int  value 
)

Append an integer to an array.

Parameters
array[in] The JSON array parent.
value[in] The integer value to append.

Definition at line 1299 of file json.c.

References JsonArrayAppendElement(), and JsonIntegerCreate().

◆ JsonArrayAppendNull()

void JsonArrayAppendNull ( JsonElement array)

Append null to an array.

Parameters
array[in] The JSON array parent.

Definition at line 1311 of file json.c.

References JsonArrayAppendElement(), and JsonNullCreate().

◆ JsonArrayAppendObject()

◆ JsonArrayAppendReal()

void JsonArrayAppendReal ( JsonElement array,
double  value 
)

Append an real to an array.

Parameters
array[in] The JSON array parent.
value[in] The real value to append.

Definition at line 1305 of file json.c.

References JsonArrayAppendElement(), and JsonRealCreate().

◆ JsonArrayAppendString()

void JsonArrayAppendString ( JsonElement array,
const char *  value 
)

Append a string to an array.

Parameters
array[in] The JSON array parent.
value[in] The string value to append.

Definition at line 1287 of file json.c.

References JsonArrayAppendElement(), and JsonStringCreate().

Referenced by BodyToJson(), BuildData(), BundleContextsToJson(), BundleToJson(), BundleTypesToJson(), FnCallMapData(), FnCallToJson(), JsonParseCsvFile(), NetworkingIPv6RoutesPostProcessInfo(), NetworkingRoutesPostProcessInfo(), RlistToJson(), StringSetToJson(), and VarRefValueToJson().

◆ JsonArrayContainsOnlyPrimitives()

bool JsonArrayContainsOnlyPrimitives ( JsonElement array)

Check if an array contains only primitives.

Parameters
array[in] The JSON array parent
Returns
true if the array contains only primitives, false otherwise

Definition at line 1406 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_ARRAY, JSON_ELEMENT_TYPE_CONTAINER, JSON_ELEMENT_TYPE_PRIMITIVE, JsonArrayGet(), JsonLength(), NULL, and JsonElement_::type.

Referenced by LoadAugmentsData().

◆ JsonArrayCreate()

◆ JsonArrayGet()

◆ JsonArrayGetAsObject()

JsonElement* JsonArrayGetAsObject ( JsonElement array,
size_t  index 
)

Get an object value from an array.

Parameters
array[in] The JSON array parent
index[in] Position of the value to get
Returns
A pointer to the object value, or NULL if non-existent.

Definition at line 1378 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_ARRAY, JSON_CONTAINER_TYPE_OBJECT, JSON_ELEMENT_TYPE_CONTAINER, NULL, SeqAt(), SeqLength(), and JsonElement_::type.

Referenced by BundleAppendPromiseTypeJson(), PolicyAppendBodyJson(), PolicyAppendBundleJson(), PolicyFromJson(), PromiseTypeAppendPromiseJson(), and RvalFromJson().

◆ JsonArrayGetAsString()

const char* JsonArrayGetAsString ( JsonElement array,
size_t  index 
)

Get a string value from an array.

Parameters
array[in] The JSON array parent
index[in] Position of the value to get
Returns
A pointer to the string value, or NULL if non-existent.

Definition at line 1359 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_ARRAY, JSON_ELEMENT_TYPE_CONTAINER, JSON_ELEMENT_TYPE_PRIMITIVE, JSON_PRIMITIVE_TYPE_STRING, NULL, JsonElement_::primitive, SeqAt(), SeqLength(), and JsonElement_::type.

Referenced by BuildData(), PolicyAppendBodyJson(), and PolicyAppendBundleJson().

◆ JsonArrayRemoveRange()

void JsonArrayRemoveRange ( JsonElement array,
size_t  start,
size_t  end 
)

Remove an inclusive range from a JSON array.

See also
SequenceRemoveRange
Parameters
array[in] The JSON array parent.
start[in] Index of the first element to remove.
end[in] Index of the last element to remove.

Definition at line 1347 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_ARRAY, JSON_ELEMENT_TYPE_CONTAINER, NULL, SeqLength(), SeqRemoveRange(), and JsonElement_::type.

Referenced by BuildData().

◆ JsonAt()

◆ JsonBoolCreate()

◆ JsonCompare()

◆ JsonContainerReverse()

void JsonContainerReverse ( JsonElement array)

◆ JsonCopy()

◆ JsonDecodeString()

char* JsonDecodeString ( const char *  escaped_string)

◆ JsonDestroy()

◆ JsonDestroyMaybe()

void JsonDestroyMaybe ( JsonElement element,
bool  allocated 
)

Destroy a JSON element if needed.

Parameters
element[in] The JSON element to destroy.
allocated[in] Whether the element was allocated and needs to be destroyed.

Definition at line 422 of file json.c.

References JsonDestroy().

Referenced by FilterInternal(), FnArgsToTm(), FnCallDataExpand(), FnCallFileSexist(), FnCallFold(), FnCallGetIndices(), FnCallGetValues(), FnCallJoin(), FnCallLength(), FnCallMakerule(), FnCallMapData(), FnCallMapList(), FnCallNth(), FnCallSetop(), FnCallShuffle(), FnCallSort(), FnCallStoreJson(), FnCallStringMustache(), FnCallSublist(), and FnCallUrlGet().

◆ JsonElementGetPropertyName()

const char* JsonElementGetPropertyName ( const JsonElement element)

Definition at line 111 of file json.c.

References NULL, and JsonElement_::propertyName.

Referenced by Render().

◆ JsonEncodeString()

char* JsonEncodeString ( const char *const  unescaped_string)

Definition at line 926 of file json.c.

References JsonEncodeStringWriter(), StringWriter(), and StringWriterClose().

Referenced by JsonPrimitiveWrite().

◆ JsonGetContainerType()

◆ JsonGetElementType()

◆ JsonGetPrimitiveType()

◆ JsonGetPropertyAsString()

const char* JsonGetPropertyAsString ( const JsonElement element)

Definition at line 796 of file json.c.

References NULL, and JsonElement_::propertyName.

Referenced by FnCallMapData(), and VarRefValueToJson().

◆ JsonGetType()

◆ JsonIntegerCreate()

JsonElement* JsonIntegerCreate ( int  value)

◆ JsonIteratorCurrentContainerType()

JsonContainerType JsonIteratorCurrentContainerType ( const JsonIterator iter)

◆ JsonIteratorCurrentElementType()

JsonElementType JsonIteratorCurrentElementType ( const JsonIterator iter)

Definition at line 630 of file json.c.

References JsonIteratorCurrentValue(), NULL, and JsonElement_::type.

◆ JsonIteratorCurrentKey()

◆ JsonIteratorCurrentPrimitiveType()

JsonPrimitiveType JsonIteratorCurrentPrimitiveType ( const JsonIterator iter)

◆ JsonIteratorCurrentValue()

◆ JsonIteratorHasMore()

bool JsonIteratorHasMore ( const JsonIterator iter)

Definition at line 660 of file json.c.

References JsonIterator::container, JsonIterator::index, JsonLength(), and NULL.

◆ JsonIteratorInit()

◆ JsonIteratorNextKey()

◆ JsonIteratorNextValue()

◆ JsonIteratorNextValueByType()

◆ JsonLength()

◆ JsonMerge()

◆ JsonNullCreate()

◆ JsonObjectAppendArray()

void JsonObjectAppendArray ( JsonElement object,
const char *  key,
JsonElement array 
)

Append an array field to an object.

Parameters
object[in] The JSON object parent.
key[in] the key of the field.
value[in] The value of the field.

Definition at line 1089 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_ARRAY, JSON_ELEMENT_TYPE_CONTAINER, JsonObjectAppendElement(), NULL, and JsonElement_::type.

Referenced by AttributeValueToJson(), BodyToJson(), BuildData(), BundleContextsToJson(), BundleToJson(), CreateContextAsJson(), FnCallToJson(), FnCallTypeToJson(), JsonBundleTypeNew(), JsonParseAsObject(), PolicyToJson(), and VarRefValueToJson().

◆ JsonObjectAppendBool()

void JsonObjectAppendBool ( JsonElement object,
const char *  key,
_Bool  value 
)
Parameters
object[in] The JSON object parent.
key[in] the key of the field.
value[in] The value of the field.

Definition at line 1069 of file json.c.

References JsonBoolCreate(), and JsonObjectAppendElement().

Referenced by DefaultTemplateData(), FnCallTypeToJson(), FnCallUrlGet(), and NetworkingRoutesPostProcessInfo().

◆ JsonObjectAppendElement()

◆ JsonObjectAppendInteger()

void JsonObjectAppendInteger ( JsonElement object,
const char *  key,
int  value 
)

Append an integer field to an object.

Parameters
object[in] The JSON object parent.
key[in] the key of the field.
value[in] The value of the field.

Definition at line 1062 of file json.c.

References JsonIntegerCreate(), and JsonObjectAppendElement().

Referenced by BodyContextsToJson(), BodyToJson(), BundleContextsToJson(), BundleToJson(), EvalContextGetPromiseCallers(), FnCallProcessExists(), FnCallUrlGet(), GetNetworkingInfo(), GetUserInfo(), JsonExtractParsedNumber(), ReadPolicyValidatedFile(), and WritePolicyValidatedFile().

◆ JsonObjectAppendNull()

void JsonObjectAppendNull ( JsonElement object,
const char *  key 
)

Append null field to an object.

Parameters
object[in] The JSON object parent.
key[in] the key of the field.

Definition at line 1083 of file json.c.

References JsonNullCreate(), and JsonObjectAppendElement().

◆ JsonObjectAppendObject()

void JsonObjectAppendObject ( JsonElement object,
const char *  key,
JsonElement childObject 
)

◆ JsonObjectAppendReal()

void JsonObjectAppendReal ( JsonElement object,
const char *  key,
double  value 
)

Append an real number field to an object.

Parameters
object[in] The JSON object parent.
key[in] the key of the field.
value[in] The value of the field.

Definition at line 1076 of file json.c.

References JsonObjectAppendElement(), and JsonRealCreate().

◆ JsonObjectAppendString()

◆ JsonObjectCreate()

◆ JsonObjectDetachKey()

JsonElement* JsonObjectDetachKey ( JsonElement object,
const char *  key 
)

Detach json element ownership from parent object;.

Parameters
objectcontaining the key property
propertyname to be detached

Definition at line 1183 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_OBJECT, JSON_ELEMENT_TYPE_CONTAINER, JsonElementHasProperty(), JsonElementIndexInParentObject(), NULL, SeqLookup(), SeqSoftRemove(), and JsonElement_::type.

◆ JsonObjectGet()

◆ JsonObjectGetAsArray()

JsonElement* JsonObjectGetAsArray ( JsonElement object,
const char *  key 
)

Get the value of a field in an object, as an array.

Parameters
object[in] The JSON object parent.
key[in] the key of the field.
Returns
A pointer to the array value, or NULL if non-existent.

Definition at line 1245 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_ARRAY, JSON_CONTAINER_TYPE_OBJECT, JSON_ELEMENT_TYPE_CONTAINER, JsonElementHasProperty(), NULL, SeqLookup(), and JsonElement_::type.

Referenced by BundleAppendPromiseTypeJson(), BundleTypesToJson(), FnCallUrlGet(), PolicyAppendBodyJson(), PolicyAppendBundleJson(), PolicyFromJson(), PromiseTypeAppendPromiseJson(), and RvalFromJson().

◆ JsonObjectGetAsObject()

JsonElement* JsonObjectGetAsObject ( JsonElement object,
const char *  key 
)

Get the value of a field in an object, as an object.

Parameters
object[in] The JSON object parent.
key[in] the key of the field.
Returns
A pointer to the object value, or NULL if non-existent.

Definition at line 1224 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_OBJECT, JSON_ELEMENT_TYPE_CONTAINER, JsonElementHasProperty(), NULL, SeqLookup(), and JsonElement_::type.

Referenced by BodyAppendConstraintJson(), BundleTypesToJson(), DefaultTemplateData(), FnCallUrlGet(), and PromiseAppendConstraintJson().

◆ JsonObjectGetAsString()

◆ JsonObjectRemoveKey()

bool JsonObjectRemoveKey ( JsonElement object,
const char *  key 
)

Remove key from the object.

Parameters
objectcontaining the key property
propertyname to be removed
Returns
True if key was removed

Definition at line 1167 of file json.c.

References JsonElement_::container, JSON_CONTAINER_TYPE_OBJECT, JSON_ELEMENT_TYPE_CONTAINER, JsonElementIndexInParentObject(), NULL, SeqRemove(), and JsonElement_::type.

Referenced by JsonExtractParsedNumber(), JsonObjectAppendElement(), JsonRewriteParsedIPAddress(), and NetworkingPortsPostProcessInfo().

◆ JsonParse()

JsonParseError JsonParse ( const char **  data,
JsonElement **  json_out 
)

Parse a string to create a JsonElement.

Parameters
data[in] Pointer to the string to parse
json_outResulting JSON object
Returns
See JsonParseError and JsonParseErrorToString

Definition at line 2648 of file json.c.

References JsonParseWithLookup(), and NULL.

Referenced by Cf3ParseFile(), ExecJSON_Pipe(), JsonParseAnyFile(), ModuleProtocol(), and yyparse().

◆ JsonParseAnyFile()

JsonParseError JsonParseAnyFile ( const char *  path,
size_t  size_max,
JsonElement **  json_out,
bool  yaml_format 
)

Convenience function to parse JSON or YAML from a file.

Parameters
pathPath to the file
size_maxMaximum size to read in memory
json_outResulting JSON object
yaml_formatWhether or not the file is in yaml format
Returns
See JsonParseError and JsonParseErrorToString

Definition at line 2691 of file json.c.

Referenced by JsonParseFile().

◆ JsonParseErrorToString()

◆ JsonParseFile()

JsonParseError JsonParseFile ( const char *  path,
size_t  size_max,
JsonElement **  json_out 
)

Convenience function to parse JSON from a file.

Parameters
pathPath to the file
size_maxMaximum size to read in memory
json_outResulting JSON object
Returns
See JsonParseError and JsonParseErrorToString

Definition at line 2727 of file json.c.

References JsonParseAnyFile().

Referenced by ReadJsonFile(), and ReadReleaseIdFileFromInputs().

◆ JsonParseWithLookup()

JsonParseError JsonParseWithLookup ( void *  lookup_data,
JsonLookup lookup_function,
const char **  data,
JsonElement **  json_out 
)

Parse a string to create a JsonElement.

Parameters
lookup_data[in] Evaluation context for variable lookups
lookup_function[in] Callback function for variable lookups
data[in] Pointer to the string to parse
json_outResulting JSON object
Returns
See JsonParseError and JsonParseErrorToString

The lookup_context type is void so we don't have to include eval_context.h from libpromises into libutil

Definition at line 2653 of file json.c.

References IsWhitespace(), JSON_PARSE_ERROR_NO_DATA, JsonParseAsArray(), JsonParseAsObject(), JsonParseAsPrimitive(), and NULL.

Referenced by FnCallGetIndices(), FnCallMapData(), FnCallParseJson(), JsonParse(), and VarNameOrInlineToJson().

◆ JsonPrimitiveGetAsBool()

◆ JsonPrimitiveGetAsInt64()

int JsonPrimitiveGetAsInt64 ( const JsonElement primitive,
int64_t *  value_out 
)

◆ JsonPrimitiveGetAsInt64DefaultOnError()

int64_t JsonPrimitiveGetAsInt64DefaultOnError ( const JsonElement primitive,
int64_t  default_return 
)

◆ JsonPrimitiveGetAsInt64ExitOnError()

int64_t JsonPrimitiveGetAsInt64ExitOnError ( const JsonElement primitive)

◆ JsonPrimitiveGetAsInteger()

◆ JsonPrimitiveGetAsReal()

◆ JsonPrimitiveGetAsString()

◆ JsonPrimitiveToString()

◆ JsonPrimitiveTypeToString()

const char* JsonPrimitiveTypeToString ( JsonPrimitiveType  type)

◆ JsonRealCreate()

JsonElement* JsonRealCreate ( double  value)

◆ JsonSelect()

◆ JsonSort()

void JsonSort ( const JsonElement container,
JsonComparator Compare,
void *  user_data 
)

◆ JsonStringCreate()

◆ JsonWrite()

void JsonWrite ( Writer writer,
const JsonElement element,
size_t  indent_level 
)

Pretty-print a JsonElement recursively into a Writer. If it's a JsonObject, its children will be sorted to produce canonical JSON output, but the object's contents are not modified so it's still a const.

See also
Writer
Parameters
writer[in] The Writer object to use as a buffer.
element[in] The JSON element to print.
indent_level[in] The nesting level with which the printing should be done. This is mainly to allow the function to be called recursively. Clients will normally want to set this to 0.

Definition at line 1701 of file json.c.

References JSON_ELEMENT_TYPE_CONTAINER, JSON_ELEMENT_TYPE_PRIMITIVE, JsonContainerWrite(), JsonPrimitiveWrite(), NULL, JsonElement_::type, and UnexpectedError.

Referenced by CheckOpts(), DefaultTemplateData(), ExecJSON_Pipe(), FnCallStoreJson(), main(), RenderVariableContainer(), RvalWriteParts(), WritePolicyValidatedFile(), and WriteReleaseIdFile().

◆ JsonWriteCompact()