SOMHunter Core
json-helpers.hpp File Reference

Implements convenience helper functions for JSON parsing. More...

#include <sstream>
#include <nlohmann/json.hpp>
#include "common.h"
Include dependency graph for json-helpers.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 sh
 

Functions

void sh::require_value (const json &json, const std::string &msg="Missing JSON value")
 Makes sure that the given json is defined (not null and not undefined). More...
 
void sh::require_key (const json &json, const std::string &key)
 Makes sure that the given json has the given key and the key is not null. More...
 
template<typename T_ >
T_ sh::optional_value_or (const json &j, const std::string &key, const T_ &or_val)
 Parses the (potentialy null) value from the given key in JSON structure and if not defined or null uses the or_val value. More...
 
template<>
std::string sh::optional_value_or (const json &j, const std::string &key, const std::string &or_val)
 Parses the (potentialy null) value from the given key in JSON structure and if not defined or null uses the or_val value. More...
 
template<typename T_ >
std::optional< T_ > sh::optional_value (const json &j, const std::string &key)
 Parses the (potentialy null) value from the given key in JSON structure. More...
 
template<>
std::optional< std::string > sh::optional_value (const json &j, const std::string &key)
 Parses the (potentialy null or empty) string from the given key in JSON structure. More...
 
json sh::wrap_and_parse (std::stringstream &in_stream)
 

Detailed Description

Implements convenience helper functions for JSON parsing.