6 #include <nlohmann/json.hpp> 10 using json = nlohmann::json;
13 const std::string& filename);
29 [[nodiscard]]
bool empty()
const;
30 [[nodiscard]] size_type count(
const std::string&)
const;
31 [[nodiscard]] std::string dump(
int = -1)
const;
32 [[nodiscard]]
bool is_object()
const;
35 json at(
const std::string&);
36 json operator[](
const std::string&);
37 void erase(
const std::string&);
39 template <
class T>
T value(
const std::string& key,
const T& fallback)
41 return (count(key) > 0) ? at(key).get<
T>() : fallback;
46 int number_of_digits = 3);
48 int number_of_digits = 3);
51 const std::string& key);
71 template <
typename T> std::optional<T>
get_optional(
const json& j, std::string_view key)
73 if (
const auto it = j.find(key); it != j.end()) {
nlohmann::json json
JSON object.
Definition: json_support.h:10
double T
floating point size
Definition: units.h:73
json loadJSON(const std::string &filename)
Read json filename into json object (w. syntax check)
std::optional< T > get_optional(const json &j, std::string_view key)
Extract JSON value associated with key into std::optional
Definition: json_support.h:71
std::tuple< const std::string &, const json & > jsonSingleItem(const json &j)
Returns a key-value pair from a JSON object which contains a single key.
void roundJSON(json &j, int number_of_digits=3)
Round float objects to n number of significant digits.
Cell list class templates.
Definition: actions.cpp:11
double roundValue(double value, int number_of_digits=3)
Round to n number of significant digits.
Like json, but delete entries after access.
Definition: json_support.h:26
double getValueInfinity(const json &j, const std::string &key)
Extract floating point from json and allow for 'inf' and '-inf'.