Contains common functions related to JSON manipulation.
More...
#include "exceptions.hpp"
#include <json/single_include/nlohmann/json.hpp>
#include <stdlib.h>
Go to the source code of this file.
Contains common functions related to JSON manipulation.
◆ object
Masks the use of nlohmann namespace in favor or an implementation-agnostic naming
◆ 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] | json | The json object to look into |
| [in] | key | The 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] | json | The json object to look into |
| [in] | key | The 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] | json | The json object to look into |
| [in] | key | The 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] | json | The json object to look into |
| [in] | key | The 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] | json | The json object to look into |
| [in] | key | The 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] | json | The json object to look into |
| [in] | key | The key to look for inside the json object |
- Returns
- A string contained in the key