Free Electron
Classes | Typedefs | Enumerations | Functions
Json Namespace Reference

JSON (JavaScript Object Notation). More...

Classes

class  CharReader
 Interface for reading JSON from a char array. More...
 
class  CharReaderBuilder
 Build a CharReader implementation. More...
 
class  Exception
 Base class for all exceptions we throw. More...
 
class  FastWriter
 Outputs a Value in JSON format without formatting (not human friendly). More...
 
class  Features
 Configuration passed to reader and writer. More...
 
class  LogicError
 Exceptions thrown by JSON_ASSERT/JSON_FAIL macros. More...
 
class  Path
 Experimental and untested: represents a "path" to access a node. More...
 
class  PathArgument
 Experimental and untested: represents an element of the "path" to access a node. More...
 
class  Reader
 Unserialize a JSON document into a Value. More...
 
class  RuntimeError
 Exceptions which the user cannot easily avoid. More...
 
class  StaticString
 Lightweight wrapper to tag static string. More...
 
class  StreamWriter
 Usage: More...
 
class  StreamWriterBuilder
 Build a StreamWriter implementation. More...
 
class  StyledStreamWriter
 Writes a Value in JSON format in a human friendly way, to a stream rather than to a string. More...
 
class  StyledWriter
 Writes a Value in JSON format in a human friendly way. More...
 
class  Value
 Represents a JSON value. More...
 
class  ValueConstIterator
 const iterator for object and array value. More...
 
class  ValueIterator
 Iterator for object and array value. More...
 
class  ValueIteratorBase
 base class for Value iterators. More...
 
class  Writer
 Abstract class for writers. More...
 

Typedefs

using Int = int
 
using UInt = unsigned int
 
using Int64 = int64_t
 
using UInt64 = uint64_t
 
using LargestInt = Int64
 
using LargestUInt = UInt64
 
template<typename T >
using Allocator = typename std::conditional< JSONCPP_USING_SECURE_MEMORY, SecureAllocator< T >, std::allocator< T > >::type
 
using String = std::basic_string< char, std::char_traits< char >, Allocator< char > >
 
using IStringStream = std::basic_istringstream< String::value_type, String::traits_type, String::allocator_type >
 
using OStringStream = std::basic_ostringstream< String::value_type, String::traits_type, String::allocator_type >
 
using IStream = std::istream
 
using OStream = std::ostream
 
using ArrayIndex = unsigned int
 
using UIntToStringBuffer = char[uintToStringBufferSize]
 

Enumerations

enum  ValueType {
  nullValue = 0,
  intValue,
  uintValue,
  realValue,
  stringValue,
  booleanValue,
  arrayValue,
  objectValue
}
 Type of the value held by a Value object. More...
 
enum  CommentPlacement {
  commentBefore = 0,
  commentAfterOnSameLine,
  commentAfter,
  numberOfCommentPlacement
}
 
enum  PrecisionType {
  significantDigits = 0,
  decimalPlaces
}
 Type of precision for formatting of real values. More...
 
enum  { uintToStringBufferSize = 3 * sizeof(LargestUInt) + 1 }
 

Functions

template<typename T , typename U >
bool operator== (const SecureAllocator< T > &, const SecureAllocator< U > &)
 
template<typename T , typename U >
bool operator!= (const SecureAllocator< T > &, const SecureAllocator< U > &)
 
bool JSON_API parseFromStream (CharReader::Factory const &, IStream &, Value *root, String *errs)
 Consume entire stream and use its begin/end. More...
 
JSON_API IStream & operator>> (IStream &, Value &)
 Read from 'sin' into 'root'. More...
 
JSONCPP_NORETURN void throwRuntimeError (String const &msg)
 used internally More...
 
JSONCPP_NORETURN void throwLogicError (String const &msg)
 used internally More...
 
void swap (Value &a, Value &b)
 
String JSON_API writeString (StreamWriter::Factory const &factory, Value const &root)
 Write into stringstream, then return string, for convenience. More...
 
String JSON_API valueToString (Int value)
 
String JSON_API valueToString (UInt value)
 
String JSON_API valueToString (LargestInt value)
 
String JSON_API valueToString (LargestUInt value)
 
String JSON_API valueToString (double value, unsigned int precision=Value::defaultRealPrecision, PrecisionType precisionType=PrecisionType::significantDigits)
 
String JSON_API valueToString (bool value)
 
String JSON_API valueToQuotedString (const char *value)
 
JSON_API OStream & operator<< (OStream &, const Value &root)
 Output using the StyledStreamWriter. More...
 
static char getDecimalPoint ()
 
static String codePointToUTF8 (unsigned int cp)
 Converts a unicode code-point to UTF-8. More...
 
static void uintToString (LargestUInt value, char *&current)
 Converts an unsigned integer to string. More...
 
template<typename Iter >
Iter fixNumericLocale (Iter begin, Iter end)
 Change ',' to '. More...
 
template<typename Iter >
void fixNumericLocaleInput (Iter begin, Iter end)
 
template<typename Iter >
Iter fixZerosInTheEnd (Iter begin, Iter end, unsigned int precision)
 Return iterator that would be the new end of the range [begin,end), if we were to delete zeros in the end of string, but not the last zero before '. More...
 

Detailed Description

JSON (JavaScript Object Notation).

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
uintToStringBufferSize 

Constant that specify the size of the buffer that must be passed to uintToString.

◆ CommentPlacement

Enumerator
commentBefore 

a comment placed on the line before a value

commentAfterOnSameLine 

a comment just after a value on the same line

commentAfter 

a comment on the line after a value (only make sense for

numberOfCommentPlacement 

root value)

◆ PrecisionType

Type of precision for formatting of real values.

Enumerator
significantDigits 

we set max number of significant digits in string

decimalPlaces 

we set max number of digits after "." in string

◆ ValueType

Type of the value held by a Value object.

Enumerator
nullValue 

'null' value

intValue 

signed integer value

uintValue 

unsigned integer value

realValue 

double value

stringValue 

UTF-8 string value.

booleanValue 

bool value

arrayValue 

array value (ordered list)

objectValue 

object value (collection of name/value pairs).

Function Documentation

◆ codePointToUTF8()

static String Json::codePointToUTF8 ( unsigned int  cp)
inlinestatic

Converts a unicode code-point to UTF-8.

◆ fixNumericLocale()

template<typename Iter >
Iter Json::fixNumericLocale ( Iter  begin,
Iter  end 
)

Change ',' to '.

' everywhere in buffer.

We had a sophisticated way, but it did not work in WinCE.

See also
https://github.com/open-source-parsers/jsoncpp/pull/9

◆ fixZerosInTheEnd()

template<typename Iter >
Iter Json::fixZerosInTheEnd ( Iter  begin,
Iter  end,
unsigned int  precision 
)

Return iterator that would be the new end of the range [begin,end), if we were to delete zeros in the end of string, but not the last zero before '.

'.

◆ operator<<()

JSON_API OStream& Json::operator<< ( OStream &  ,
const Value root 
)

Output using the StyledStreamWriter.

See also
Json::operator>>()

◆ operator>>()

JSON_API IStream& Json::operator>> ( IStream &  ,
Value  
)

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;

Result:

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

◆ parseFromStream()

bool JSON_API Json::parseFromStream ( CharReader::Factory const &  ,
IStream &  ,
Value root,
String *  errs 
)

Consume entire stream and use its begin/end.

Someday we might have a real StreamReader, but for now this is convenient.

◆ throwLogicError()

JSONCPP_NORETURN void Json::throwLogicError ( String const &  msg)

used internally

◆ throwRuntimeError()

JSONCPP_NORETURN void Json::throwRuntimeError ( String const &  msg)

used internally

◆ uintToString()

static void Json::uintToString ( LargestUInt  value,
char *&  current 
)
inlinestatic

Converts an unsigned integer to string.

Parameters
valueUnsigned integer to convert to string
currentInput/Output string buffer. Must have at least uintToStringBufferSize chars free.

◆ writeString()

String JSON_API Json::writeString ( StreamWriter::Factory const &  factory,
Value const &  root 
)

Write into stringstream, then return string, for convenience.

A StreamWriter will be created from the factory, used, and then deleted.