Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
json-utils.hh File Reference
#include <nlohmann/json.hpp>
#include "nix/util/error.hh"
#include "nix/util/types.hh"
#include "nix/util/json-non-null.hh"

Go to the source code of this file.

Classes

struct  nlohmann::adl_serializer< std::optional< T > >

Functions

const nlohmann::json & nix::valueAt (const nlohmann::json::object_t &map, std::string_view key)
const nlohmann::json * nix::optionalValueAt (const nlohmann::json::object_t &value, std::string_view key)
const nlohmann::json & nix::valueAt (nlohmann::json::object_t &&map, std::string_view key)=delete
const nlohmann::json * nix::optionalValueAt (nlohmann::json::object_t &&value, std::string_view key)=delete
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_unsigned_t & nix::getUnsigned (const nlohmann::json &value)
template<typename T>
auto nix::getInteger (const nlohmann::json &value) -> std::enable_if_t< std::is_signed_v< T > &&std::is_integral_v< T >, T >
template<typename... Args>
std::map< std::string, Args... > nix::getMap (const nlohmann::json::object_t &jsonObject, auto &&f)
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/

◆ optionalValueAt()

const nlohmann::json * nix::optionalValueAt ( const nlohmann::json::object_t & value,
std::string_view key )
Returns
A pointer to the value associated with key if value contains key, otherwise return nullptr (not JSON null!).

◆ valueAt() [1/2]

const nlohmann::json & nix::valueAt ( const nlohmann::json::object_t & map,
std::string_view 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.

◆ valueAt() [2/2]

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

Prevents bugs; see get for the same trick.