Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
json-utils.hh File Reference
#include <nlohmann/json.hpp>
#include <list>
#include "types.hh"

Go to the source code of this file.

Classes

struct  nix::json_avoids_null< T >
 
struct  nix::json_avoids_null< std::nullptr_t >
 
struct  nix::json_avoids_null< bool >
 
struct  nix::json_avoids_null< std::string >
 
struct  nix::json_avoids_null< std::vector< T > >
 
struct  nix::json_avoids_null< std::list< T > >
 
struct  nix::json_avoids_null< std::map< K, V > >
 
struct  nix::json_avoids_null< ExperimentalFeature >
 
struct  nlohmann::adl_serializer< std::optional< T > >
 

Functions

const nlohmann::json * nix::get (const nlohmann::json &map, const std::string &key)
 
nlohmann::json * nix::get (nlohmann::json &map, const std::string &key)
 
const nlohmann::json & nix::valueAt (const nlohmann::json::object_t &map, const std::string &key)
 
std::optional< nlohmann::json > nix::optionalValueAt (const nlohmann::json::object_t &map, const std::string &key)
 
const nlohmann::json * nix::getNullable (const nlohmann::json &value)
 
const nlohmann::json::object_t & nix::getObject (const nlohmann::json &value)
 
const nlohmann::json::array_t & nix::getArray (const nlohmann::json &value)
 
const nlohmann::json::string_t & nix::getString (const nlohmann::json &value)
 
const nlohmann::json::number_integer_t & nix::getInteger (const nlohmann::json &value)
 
const nlohmann::json::boolean_t & nix::getBoolean (const nlohmann::json &value)
 
Strings nix::getStringList (const nlohmann::json &value)
 
StringMap nix::getStringMap (const nlohmann::json &value)
 
StringSet nix::getStringSet (const nlohmann::json &value)
 

Function Documentation

◆ getNullable()

const nlohmann::json * nix::getNullable ( const nlohmann::json & value)

Downcast the json object, failing with a nice error if the conversion fails. See https://json.nlohmann.me/features/types/

◆ valueAt()

const nlohmann::json & nix::valueAt ( const nlohmann::json::object_t & map,
const std::string & key )

Get the value of a json object at a key safely, failing with a nice error if the key does not exist.

Use instead of nlohmann::json::at() to avoid ugly exceptions.