jaffarCommon
Loading...
Searching...
No Matches
Typedefs | Functions
json.hpp File Reference

Contains common functions related to JSON manipulation. More...

#include "exceptions.hpp"
#include <json/single_include/nlohmann/json.hpp>
#include <stdlib.h>
Include dependency graph for json.hpp:

Go to the source code of this file.

Typedefs

typedef nlohmann::json jaffarCommon::json::object
 

Functions

__JAFFAR_COMMON__INLINE__ const void jaffarCommon::json::checkEntry (const object &json, const std::string &key)
 
__JAFFAR_COMMON__INLINE__ const std::string jaffarCommon::json::getString (const object &json, const std::string &key)
 
__JAFFAR_COMMON__INLINE__ const objectjaffarCommon::json::getObject (const object &json, const std::string &key)
 
template<typename T >
__JAFFAR_COMMON__INLINE__ const std::vector< T > jaffarCommon::json::getArray (const object &json, const std::string &key)
 
template<typename T >
__JAFFAR_COMMON__INLINE__ const T jaffarCommon::json::getNumber (const object &json, const std::string &key)
 
__JAFFAR_COMMON__INLINE__ const bool jaffarCommon::json::getBoolean (const object &json, const std::string &key)
 

Detailed Description

Contains common functions related to JSON manipulation.

Typedef Documentation

◆ object

typedef nlohmann::json jaffarCommon::json::object

Masks the use of nlohmann namespace in favor or an implementation-agnostic naming

Function Documentation

◆ checkEntry()

__JAFFAR_COMMON__INLINE__ const void jaffarCommon::json::checkEntry ( const object json,
const std::string &  key 
)

Verifies the given key exists in the given json object

Note
An exception will occur if the input is not a json object (e.g., is an array)
An exception will occur if the given key does not exist in the json object
Parameters
[in]jsonThe json object to look into
[in]keyThe key to look for inside the json object

◆ getArray()

template<typename T >
__JAFFAR_COMMON__INLINE__ const std::vector< T > jaffarCommon::json::getArray ( const object json,
const std::string &  key 
)

Returns the array of the specified type stored in the given key of the given json object

Note
An exception will occur if the input is not a json object (e.g., is an array)
An exception will occur if the given key does not exist in the json object
An exception will occur if the given key is not an array
Parameters
[in]jsonThe json object to look into
[in]keyThe key to look for inside the json object
Returns
A vector of the type specified containing all the elements of the array of key entry

◆ getBoolean()

__JAFFAR_COMMON__INLINE__ const bool jaffarCommon::json::getBoolean ( const object json,
const std::string &  key 
)

Returns the boolean stored the given key of the given json object

Note
An exception will occur if the input is not a json object (e.g., is an array)
An exception will occur if the given key does not exist in the json object
An exception will occur if the given key is not a boolean
Parameters
[in]jsonThe json object to look into
[in]keyThe key to look for inside the json object
Returns
The boolean stored in the key entry

◆ getNumber()

template<typename T >
__JAFFAR_COMMON__INLINE__ const T jaffarCommon::json::getNumber ( const object json,
const std::string &  key 
)

Returns the number of the specified type stored the given key of the given json object

Note
An exception will occur if the input is not a json object (e.g., is an array)
An exception will occur if the given key does not exist in the json object
An exception will occur if the given key is not a number
Parameters
[in]jsonThe json object to look into
[in]keyThe key to look for inside the json object
Returns
The number stored in the key entry

◆ getObject()

__JAFFAR_COMMON__INLINE__ const object & jaffarCommon::json::getObject ( const object json,
const std::string &  key 
)

Returns the object stored in the given key of the given json object

Note
An exception will occur if the input is not a json object (e.g., is an array)
An exception will occur if the given key does not exist in the json object
An exception will occur if the given key is not an object
Parameters
[in]jsonThe json object to look into
[in]keyThe key to look for inside the json object
Returns
A json object contained in the key

◆ getString()

__JAFFAR_COMMON__INLINE__ const std::string jaffarCommon::json::getString ( const object json,
const std::string &  key 
)

Returns the string stored in the given key of the given json object

Note
An exception will occur if the input is not a json object (e.g., is an array)
An exception will occur if the given key does not exist in the json object
An exception will occur if the given key is not a string
Parameters
[in]jsonThe json object to look into
[in]keyThe key to look for inside the json object
Returns
A string contained in the key