djson v3.1.3
JSON parser
 
Loading...
Searching...
No Matches
dj Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  Error
 Various kinds of parse and IO errors. Contains contextual token and source location if parse error. More...
 
class  Json
 Library interface, represents a valid JSON value. More...
 
struct  SerializeFlag
 Bit flags for serialization options. More...
 
struct  SerializeOptions
 Serialization options. More...
 
struct  SrcLoc
 Source location. More...
 
struct  StringHash
 Heterogeneous string hasher. More...
 

Concepts

concept  NumericT
 Numeric type.
 
concept  StringyT
 Stringy type.
 
concept  GettableT
 Type to obtain JSON value as.
 
concept  SettableT
 Type to set JSON value to.
 

Typedefs

using Result = std::expected< Json, Error >
 Parse result type.
 
using SerializeFlags = decltype(std::to_underlying(SerializeFlag::None))
 
template<typename Value >
using StringTable = std::unordered_map< std::string, Value, StringHash, std::equal_to<> >
 Heterogeneous string map.
 

Enumerations

enum class  JsonType : std::int8_t {
  Null , Boolean , Number , String ,
  Array , Object , COUNT_
}
 JSON value type. More...
 
enum class  ParseMode : std::int8_t { Auto , Strict , Jsonc }
 Parse mode. More...
 

Functions

auto to_string_view (Error::Type type) -> std::string_view
 Obtain stringified Error Type.
 
auto to_string (Error const &error) -> std::string
 Obtain print-friendly error string.
 
auto to_string (Json const &json, SerializeOptions const &options={})
 
auto make_escaped (std::string_view text) -> std::string
 Convert input text to escaped string.
 
template<GettableT Type>
void from_json (Json const &json, Type &value, Type const fallback={})
 Assign JSON as value.
 
template<SettableT Type>
void to_json (Json &json, Type const &value)
 Assign value to JSON.
 

Variables

constexpr auto serialize_flags_v = SerializeFlag::SortKeys | SerializeFlag::TrailingNewline
 Default serialize flags.
 

Typedef Documentation

◆ Result

using dj::Result = typedef std::expected<Json, Error>

Parse result type.

◆ SerializeFlags

using dj::SerializeFlags = typedef decltype(std::to_underlying(SerializeFlag::None))

◆ StringTable

template<typename Value >
using dj::StringTable = typedef std::unordered_map<std::string, Value, StringHash, std::equal_to<> >

Heterogeneous string map.

Enumeration Type Documentation

◆ JsonType

enum class dj::JsonType : std::int8_t
strong

JSON value type.

Enumerator
Null 
Boolean 
Number 
String 
Array 
Object 
COUNT_ 

◆ ParseMode

enum class dj::ParseMode : std::int8_t
strong

Parse mode.

Enumerator
Auto 

Automatic: Strict unless first line specifies JSONC mode.

Strict 

Core JSON only.

Jsonc 

Allow JSONC extensions.

Function Documentation

◆ from_json()

template<GettableT Type>
void dj::from_json ( Json const &  json,
Type &  value,
Type const  fallback = {} 
)

Assign JSON as value.

◆ make_escaped()

auto dj::make_escaped ( std::string_view  text) -> std::string

Convert input text to escaped string.

◆ to_json()

template<SettableT Type>
void dj::to_json ( Json json,
Type const &  value 
)

Assign value to JSON.

◆ to_string() [1/2]

auto dj::to_string ( Error const &  error) -> std::string

Obtain print-friendly error string.

◆ to_string() [2/2]

auto dj::to_string ( Json const &  json,
SerializeOptions const &  options = {} 
)
inline

◆ to_string_view()

auto dj::to_string_view ( Error::Type  type) -> std::string_view

Obtain stringified Error Type.

Variable Documentation

◆ serialize_flags_v

constexpr auto dj::serialize_flags_v = SerializeFlag::SortKeys | SerializeFlag::TrailingNewline
inlineconstexpr

Default serialize flags.