xrpld
Loading...
Searching...
No Matches
json Namespace Reference

JSON (JavaScript Object Notation). More...

Namespaces

namespace  detail

Classes

struct  Error
class  Reader
 Unserialize a JSON document into a Value. More...
class  StaticString
 Lightweight wrapper to tag static string. More...
class  Value
 Represents a JSON value. More...
class  ValueAllocator
 Experimental do not use: Allocator to customize member name and string value memory management done by Value. More...
class  ValueIteratorBase
 base class for Value iterators. More...
class  ValueConstIterator
 const iterator for object and array value. More...
class  ValueIterator
 Iterator for object and array value. More...
class  WriterBase
 Abstract class for writers. More...
class  FastWriter
 Outputs a Value in JSON format without formatting (not human friendly). More...
class  StyledWriter
 Writes a Value in JSON format in a human friendly way. More...
class  StyledStreamWriter
 Writes a Value in JSON format in a human friendly way, to a stream rather than to a string. More...
class  Compact
 Decorator for streaming out compact json. More...
class  Writer
 Writer implements an O(1)-space, O(1)-granular output JSON writer. More...
struct  JsonMissingKeyError
struct  JsonTypeMismatchError
class  DefaultValueAllocator
struct  DummyValueAllocatorInitializer

Typedefs

using Int = int
using UInt = unsigned int
using Output = std::function<void(boost::beast::string_view const&)>

Enumerations

enum class  ValueType {
  Null = 0 , Int , UInt , Real ,
  String , Boolean , Array , Object
}
 Type of the value held by a Value object. More...

Functions

std::istreamoperator>> (std::istream &, Value &)
 Read from 'sin' into 'root'.
bool operator== (StaticString x, StaticString y)
bool operator!= (StaticString x, StaticString y)
bool operator== (std::string const &x, StaticString y)
bool operator!= (std::string const &x, StaticString y)
bool operator== (StaticString x, std::string const &y)
bool operator!= (StaticString x, std::string const &y)
Value toJson (xrpl::Number const &number)
bool operator== (Value const &x, Value const &y)
bool operator!= (Value const &x, Value const &y)
bool operator< (Value const &x, Value const &y)
bool operator<= (Value const &x, Value const &y)
bool operator> (Value const &x, Value const &y)
bool operator>= (Value const &x, Value const &y)
std::string valueToString (Int value)
std::string valueToString (UInt value)
std::string valueToString (double value)
std::string valueToString (bool value)
std::string valueToQuotedString (char const *value)
std::ostreamoperator<< (std::ostream &, Value const &root)
 Output using the StyledStreamWriter.
template<class Write>
void stream (json::Value const &jv, Write const &write)
 Stream compact JSON to the specified function.
Output stringOutput (std::string &s)
void outputJson (json::Value const &, Output const &)
 Writes a minimal representation of a Json value to an Output in O(n) time.
std::string jsonAsString (json::Value const &)
 Return the minimal string representation of a json::Value in O(n) time.
std::string to_string (Value const &)
 Writes a json::Value to an std::string.
std::string pretty (Value const &)
 Writes a json::Value to an std::string.
void check (bool condition, std::string const &message)
template<>
xrpl::AccountID getOrThrow (json::Value const &v, xrpl::SField const &field)
template<class T>
getOrThrow (json::Value const &v, xrpl::SField const &field)
template<>
std::string getOrThrow (json::Value const &v, xrpl::SField const &field)
template<>
bool getOrThrow (json::Value const &v, xrpl::SField const &field)
template<>
std::uint64_t getOrThrow (json::Value const &v, xrpl::SField const &field)
template<>
xrpl::Buffer getOrThrow (json::Value const &v, xrpl::SField const &field)
template<class T>
std::optional< T > getOptional (json::Value const &v, xrpl::SField const &field)
template<>
xrpl::PublicKey getOrThrow (json::Value const &v, xrpl::SField const &field)
template<>
xrpl::STAmount getOrThrow (json::Value const &v, xrpl::SField const &field)
static std::string codePointToUTF8 (unsigned int cp)
static ValueAllocator *& valueAllocator ()
static int integerCmp (Int i, UInt ui)
static bool isControlCharacter (char ch)
static bool containsControlCharacter (char const *str)
static void uintToString (unsigned int value, char *&current)

Variables

static struct json::DummyValueAllocatorInitializer gDummyValueAllocatorInitializer

Detailed Description

JSON (JavaScript Object Notation).

Typedef Documentation

◆ Int

using json::Int = int

Definition at line 6 of file json_forwards.h.

◆ UInt

using json::UInt = unsigned int

Definition at line 7 of file json_forwards.h.

◆ Output

using json::Output = std::function<void(boost::beast::string_view const&)>

Definition at line 12 of file include/xrpl/json/Output.h.

Enumeration Type Documentation

◆ ValueType

enum class json::ValueType
strong

Type of the value held by a Value object.

Enumerator
Null 

'null' value

Int 

signed integer value

UInt 

unsigned integer value

Real 

double value

String 

UTF-8 string value.

Boolean 

bool value

Array 

array value (ordered list)

Object 

object value (collection of name/value pairs).

Definition at line 18 of file json_value.h.

Function Documentation

◆ operator>>()

std::istream & json::operator>> ( std::istream & sin,
Value & root )

Read from 'sin' into 'root'.

Always keep comments from the input JSON.

This can be used to read a file into a particular sub-object. For example:

cin >> root["dir"]["file"];
cout << root;
Represents a JSON value.
Definition json_value.h:130

Result:

 {
"dir": {
    "file": {
 // The input stream JSON would be nested here.
    }
}
 }
Exceptions
std::exceptionon parse error.
See also
json::operator<<()

Definition at line 925 of file json_reader.cpp.

◆ operator==() [1/4]

bool json::operator== ( StaticString x,
StaticString y )

Definition at line 67 of file json_value.h.

◆ operator!=() [1/4]

bool json::operator!= ( StaticString x,
StaticString y )

Definition at line 73 of file json_value.h.

◆ operator==() [2/4]

bool json::operator== ( std::string const & x,
StaticString y )

Definition at line 79 of file json_value.h.

◆ operator!=() [2/4]

bool json::operator!= ( std::string const & x,
StaticString y )

Definition at line 85 of file json_value.h.

◆ operator==() [3/4]

bool json::operator== ( StaticString x,
std::string const & y )

Definition at line 91 of file json_value.h.

◆ operator!=() [3/4]

bool json::operator!= ( StaticString x,
std::string const & y )

Definition at line 97 of file json_value.h.

◆ toJson()

Value json::toJson ( xrpl::Number const & number)

Definition at line 429 of file json_value.h.

◆ operator==() [4/4]

bool json::operator== ( Value const & x,
Value const & y )

Definition at line 428 of file json_value.cpp.

◆ operator!=() [4/4]

bool json::operator!= ( Value const & x,
Value const & y )

Definition at line 438 of file json_value.h.

◆ operator<()

bool json::operator< ( Value const & x,
Value const & y )

Definition at line 372 of file json_value.cpp.

◆ operator<=()

bool json::operator<= ( Value const & x,
Value const & y )

Definition at line 446 of file json_value.h.

◆ operator>()

bool json::operator> ( Value const & x,
Value const & y )

Definition at line 453 of file json_value.h.

◆ operator>=()

bool json::operator>= ( Value const & x,
Value const & y )

Definition at line 459 of file json_value.h.

◆ valueToString() [1/4]

std::string json::valueToString ( Int value)

Definition at line 48 of file json_writer.cpp.

◆ valueToString() [2/4]

std::string json::valueToString ( UInt value)

Definition at line 67 of file json_writer.cpp.

◆ valueToString() [3/4]

std::string json::valueToString ( double value)

Definition at line 77 of file json_writer.cpp.

◆ valueToString() [4/4]

std::string json::valueToString ( bool value)

Definition at line 95 of file json_writer.cpp.

◆ valueToQuotedString()

std::string json::valueToQuotedString ( char const * value)

Definition at line 101 of file json_writer.cpp.

◆ operator<<()

std::ostream & json::operator<< ( std::ostream & sout,
Value const & root )

Output using the StyledStreamWriter.

See also
json::operator>>()

Definition at line 721 of file json_writer.cpp.

◆ stream()

template<class Write>
void json::stream ( json::Value const & jv,
Write const & write )

Stream compact JSON to the specified function.

Parameters
jvThe json::Value to write
writeInvocable with signature void(void const*, std::size_t) that is called when output should be written to the stream.

Definition at line 273 of file json_writer.h.

◆ stringOutput()

Output json::stringOutput ( std::string & s)

Definition at line 15 of file include/xrpl/json/Output.h.

◆ outputJson()

void json::outputJson ( json::Value const & value,
Output const & out )

Writes a minimal representation of a Json value to an Output in O(n) time.

Data is streamed right to the output, so only a marginal amount of memory is used. This can be very important for a very large json::Value.

Definition at line 75 of file libxrpl/json/Output.cpp.

◆ jsonAsString()

std::string json::jsonAsString ( json::Value const & value)

Return the minimal string representation of a json::Value in O(n) time.

This requires a memory allocation for the full size of the output. If possible, use outputJson().

Definition at line 82 of file libxrpl/json/Output.cpp.

◆ to_string()

std::string json::to_string ( Value const & value)

Writes a json::Value to an std::string.

Definition at line 10 of file to_string.cpp.

◆ pretty()

std::string json::pretty ( Value const & value)

Writes a json::Value to an std::string.

Definition at line 16 of file to_string.cpp.

◆ check()

void json::check ( bool condition,
std::string const & message )

Definition at line 233 of file json/Writer.h.

◆ getOrThrow() [1/8]

template<>
xrpl::AccountID json::getOrThrow ( json::Value const & v,
xrpl::SField const & field )

Definition at line 111 of file AccountID.h.

◆ getOrThrow() [2/8]

template<class T>
T json::getOrThrow ( json::Value const & v,
xrpl::SField const & field )

Definition at line 55 of file json_get_or_throw.h.

◆ getOrThrow() [3/8]

template<>
std::string json::getOrThrow ( json::Value const & v,
xrpl::SField const & field )

Definition at line 62 of file json_get_or_throw.h.

◆ getOrThrow() [4/8]

template<>
bool json::getOrThrow ( json::Value const & v,
xrpl::SField const & field )

Definition at line 78 of file json_get_or_throw.h.

◆ getOrThrow() [5/8]

template<>
std::uint64_t json::getOrThrow ( json::Value const & v,
xrpl::SField const & field )

Definition at line 95 of file json_get_or_throw.h.

◆ getOrThrow() [6/8]

template<>
xrpl::Buffer json::getOrThrow ( json::Value const & v,
xrpl::SField const & field )

Definition at line 128 of file json_get_or_throw.h.

◆ getOptional()

template<class T>
std::optional< T > json::getOptional ( json::Value const & v,
xrpl::SField const & field )

Definition at line 143 of file json_get_or_throw.h.

◆ getOrThrow() [7/8]

template<>
xrpl::PublicKey json::getOrThrow ( json::Value const & v,
xrpl::SField const & field )

Definition at line 266 of file PublicKey.h.

◆ getOrThrow() [8/8]

template<>
xrpl::STAmount json::getOrThrow ( json::Value const & v,
xrpl::SField const & field )

Definition at line 790 of file STAmount.h.

◆ codePointToUTF8()

std::string json::codePointToUTF8 ( unsigned int cp)
static

Definition at line 20 of file json_reader.cpp.

◆ valueAllocator()

ValueAllocator *& json::valueAllocator ( )
static

Definition at line 65 of file json_value.cpp.

◆ integerCmp()

int json::integerCmp ( Int i,
UInt ui )
static

Definition at line 360 of file json_value.cpp.

◆ isControlCharacter()

bool json::isControlCharacter ( char ch)
static

Definition at line 19 of file json_writer.cpp.

◆ containsControlCharacter()

bool json::containsControlCharacter ( char const * str)
static

Definition at line 25 of file json_writer.cpp.

◆ uintToString()

void json::uintToString ( unsigned int value,
char *& current )
static

Definition at line 36 of file json_writer.cpp.

Variable Documentation

◆ gDummyValueAllocatorInitializer

struct json::DummyValueAllocatorInitializer json::gDummyValueAllocatorInitializer
static