Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
json_util.h File Reference
#include <stdio.h>
#include "grassroots_util_library.h"
#include "jansson.h"
#include "linked_list.h"
#include "string_linked_list.h"
#include "schema_keys.h"
Include dependency graph for json_util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  JsonNode
 A datatype for storing a json_t on a LinkedList. More...
 
struct  FieldNode
 A datatype for storing a value as a string along with the datatype to convert it to. More...
 

Functions

int PrintJSON (FILE *out_f, const json_t *const json_p, const char *const prefix_s)
 Print a json fragment to a FILE pointer. More...
 
const char * GetJSONString (const json_t *json_p, const char *const key_s)
 Get the value for a given key in a json_t object. More...
 
bool SetJSONString (json_t *json_p, const char *const key_s, const char *const value_s)
 
bool SetJSONStringOrNull (json_t *json_p, const char *const key_s, const char *const value_s, const bool null_flag)
 
char * GetCopiedJSONString (const json_t *json_p, const char *const key_s)
 Get the newly-allocated value for a given key in a json_t object. More...
 
bool GetJSONInteger (const json_t *json_p, const char *const key_s, json_int_t *value_p)
 Get the integer value for a given key in a json_t object. More...
 
bool SetJSONInteger (json_t *json_p, const char *const key_s, const json_int_t value)
 
bool GetJSONLong (const json_t *json_p, const char *const key_s, long *value_p)
 Get the long value for a given key in a json_t object. More...
 
bool GetJSONReal (const json_t *json_p, const char *const key_s, double *value_p)
 Get the double value for a given key in a json_t object. More...
 
bool SetJSONReal (json_t *json_p, const char *const key_s, const double value)
 
bool GetJSONBoolean (const json_t *json_p, const char *const key_s, bool *value_p)
 Get the boolean value for a given key in a json_t object. More...
 
bool SetJSONBoolean (json_t *json_p, const char *const key_s, const bool value)
 
bool AddStringArrayToJSON (json_t *parent_p, const char **const values_ss, const char *const child_key_s)
 Create and add an array of c-style strings to a json object. More...
 
char ** GetStringArrayFromJSON (const json_t *const array_p, bool add_terminating_null_flag)
 Created an array of c-style string of StringListNodes from a json array. More...
 
bool AddStringListToJSON (json_t *parent_p, LinkedList *values_p, const char *const child_key_s)
 Create and add a LinkedList of StringListNodes to a json object. More...
 
LinkedListGetStringListFromJSON (const json_t *const array_p)
 Created a LinkedList of StringListNodes from a json array. More...
 
json_t * LoadJSONFile (const char *const filename_s)
 Load a JSON file. More...
 
json_t * ConvertTabularDataToJSON (char *data_s, const char column_delimiter, const char row_delimiter, LinkedList *headers_p)
 Convert a string of tabular data into a JSON array using the given column headings. More...
 
json_t * ConvertTabularDataWithHeadersToJSON (char *data_s, const char column_delimiter, const char row_delimiter, json_type(*get_type_fn)(const char *name_s, const void *const data_p), const void *const type_data_p)
 Convert a string of tabular data into a JSON array. More...
 
LinkedListGetTabularHeaders (char **data_ss, const char column_delimiter, const char row_delimiter, json_type(*get_type_fn)(const char *name_s, const void *const data_p), const void *const type_data_p)
 Get the column headers from the first row of a tabular data variable. More...
 
json_t * ConvertRowToJSON (char *row_s, LinkedList *headers_p, const char delimiter)
 Create a JSON object from a delimited string of data. More...
 
bool AddValidJSONString (json_t *parent_p, const char *const key_s, const char *const value_s)
 Add a string key-value pair to a JSON object only if the value is not NULL. More...
 
int PrintJSONToLog (const uint32 level, const char *filename_s, const int line_number, const json_t *json_p, const char *message_s,...)
 Print a json_t object to the logging stream. More...
 
int PrintJSONToErrors (const uint32 level, const char *filename_s, const int line_number, const json_t *json_p, const char *message_s,...)
 Print a json_t object to the error stream. More...
 
bool IsJSONEmpty (const json_t *json_p)
 Is a json_t NULL or empty? More...
 
void PrintJSONRefCounts (const uint32 log_level, const char *const filename_s, const int line_number, const json_t *const value_p, const char *initial_s)
 Print the reference counts for all of the entries in a json_t object to the logging stream. More...
 
bool SetBooleanFromJSON (const json_t *json_p, bool *value_p)
 Set the boolean value of a JSON object. More...
 
bool SetRealFromJSON (const json_t *json_p, double *value_p)
 Get the real value of a JSON object. More...
 
bool SetIntegerFromJSON (const json_t *json_p, json_int_t *value_p)
 Get the integer value of a JSON object. More...
 
bool SetLongFromJSON (const json_t *json_p, int64 *value_p)
 Get the long value of a JSON object. More...
 
bool SetStringFromJSON (const json_t *json_p, char **value_ss)
 Get the string value of a JSON object. More...
 
bool SetJSONNull (json_t *json_p, const char *const key_s)
 Add a child key to a JSON object where the value is null. More...
 
json_t * GetCompoundJSONObject (const json_t *input_p, const char *const compound_s)
 Get a descendant JSON object from another using a given selector. More...
 
bool CopyJSONKeyStringValuePair (const json_t *src_p, json_t *dest_p, const char *const key_s, bool optional_flag)
 Make a copy of given key-value pair from one JSON object to another. More...
 
bool CopyJSONKeyIntegerValuePair (const json_t *src_p, json_t *dest_p, const char *const key_s, bool optional_flag)
 Make a copy of given key-value pair from one JSON object to another. More...
 
bool DeepCopyValidJSON (const json_t *src_p, json_t **dest_pp)
 Make a deep copy of a source JSON fragment to another. More...
 
bool AddOntologyContextTerm (json_t *root_p, const char *key_s, const char *term_s, const bool add_id_flag)
 Add a "@context" section to a JSON fragment to define a class. More...
 
json_t * SplitJSON (json_t *src_p, uint8 percentage_to_move)
 
bool GetJSONStringAsInteger (const json_t *json_p, const char *const key_s, int *answer_p)
 
bool GetJSONStringAsDouble (const json_t *json_p, const char *const key_s, double *answer_p)
 
bool GetJSONUnsignedInteger (const json_t *json_p, const char *const key_s, uint32 *value_p)
 
bool GetRealValueFromJSONString (const json_t *json_p, double64 *answer_p)
 
json_t * ConvertStringArrayToJSON (char **values_ss, const size_t num_values)
 
bool SetNonTrivialUnsignedInt (json_t *json_p, const char *key_s, const uint32 *value_p, const bool null_flag)
 
bool SetNonTrivialString (json_t *value_p, const char *key_s, const char *value_s, const bool null_flag)
 
bool SetNonTrivialDouble (json_t *json_p, const char *key_s, const double64 *value_p, const bool null_fla)
 

Function Documentation

◆ SetJSONString()

bool SetJSONString ( json_t *  json_p,
const char *const  key_s,
const char *const  value_s 
)

◆ SetJSONStringOrNull()

bool SetJSONStringOrNull ( json_t *  json_p,
const char *const  key_s,
const char *const  value_s,
const bool  null_flag 
)

◆ SetJSONInteger()

bool SetJSONInteger ( json_t *  json_p,
const char *const  key_s,
const json_int_t  value 
)

◆ SetJSONReal()

bool SetJSONReal ( json_t *  json_p,
const char *const  key_s,
const double  value 
)

◆ SetJSONBoolean()

bool SetJSONBoolean ( json_t *  json_p,
const char *const  key_s,
const bool  value 
)

◆ SplitJSON()

json_t* SplitJSON ( json_t *  src_p,
uint8  percentage_to_move 
)

◆ GetJSONStringAsInteger()

bool GetJSONStringAsInteger ( const json_t *  json_p,
const char *const  key_s,
int *  answer_p 
)

◆ GetJSONStringAsDouble()

bool GetJSONStringAsDouble ( const json_t *  json_p,
const char *const  key_s,
double *  answer_p 
)

◆ GetJSONUnsignedInteger()

bool GetJSONUnsignedInteger ( const json_t *  json_p,
const char *const  key_s,
uint32 *  value_p 
)

◆ GetRealValueFromJSONString()

bool GetRealValueFromJSONString ( const json_t *  json_p,
double64 *  answer_p 
)

◆ ConvertStringArrayToJSON()

json_t* ConvertStringArrayToJSON ( char **  values_ss,
const size_t  num_values 
)

◆ SetNonTrivialUnsignedInt()

bool SetNonTrivialUnsignedInt ( json_t *  json_p,
const char *  key_s,
const uint32 *  value_p,
const bool  null_flag 
)

◆ SetNonTrivialString()

bool SetNonTrivialString ( json_t *  value_p,
const char *  key_s,
const char *  value_s,
const bool  null_flag 
)

◆ SetNonTrivialDouble()

bool SetNonTrivialDouble ( json_t *  json_p,
const char *  key_s,
const double64 *  value_p,
const bool  null_fla 
)