ATSC3  24.10.0
Classes | Typedefs | Enumerations | Functions
Json Namespace Reference

JSON (JavaScript Object Notation). More...

Classes

class  OurFeatures
 
class  OurReader
 
class  OurCharReader
 
struct  CommentStyle
 Scoped enums are not available until C++11. More...
 
struct  BuiltStyledStreamWriter
 
class  Features
 Configuration passed to reader and writer. This configuration object can be used to force the Reader or Writer to behave in a standard conforming way. More...
 
class  Exception
 
class  RuntimeError
 
class  LogicError
 
class  StaticString
 Lightweight wrapper to tag static string. More...
 
class  Value
 Represents a JSON value. More...
 
class  PathArgument
 Experimental and untested: represents an element of the "path" to access a node. More...
 
class  Path
 Experimental and untested: represents a "path" to access a node. 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  Reader
 Unserialize a JSON document into a Value. More...
 
class  CharReader
 
class  CharReaderBuilder
 Build a CharReader implementation. More...
 
class  StreamWriter
 
class  StreamWriterBuilder
 Build a StreamWriter implementation. More...
 

Typedefs

typedef char UIntToStringBuffer[uintToStringBufferSize]
 
typedef std::auto_ptr< CharReaderCharReaderPtr
 
typedef std::auto_ptr< StreamWriterStreamWriterPtr
 
typedef int Int
 
typedef unsigned int UInt
 
typedef int64_t Int64
 
typedef uint64_t UInt64
 
typedef Int64 LargestInt
 
typedef UInt64 LargestUInt
 
typedef unsigned int ArrayIndex
 

Enumerations

enum  { uintToStringBufferSize = 3 * sizeof(LargestUInt) + 1 }
 
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...
 

Functions

template<typename Iter >
Iter fixNumericLocale (Iter begin, Iter end)
 
template<typename Iter >
void fixNumericLocaleInput (Iter begin, Iter end)
 
template<typename Iter >
Iter fixZerosInTheEnd (Iter begin, Iter end)
 
bool parseFromStream (CharReader::Factory const &fact, JSONCPP_ISTREAM &sin, Value *root, JSONCPP_STRING *errs)
 
JSONCPP_ISTREAM & operator>> (JSONCPP_ISTREAM &, Value &)
 Read from 'sin' into 'root'. More...
 
JSONCPP_NORETURN void throwRuntimeError (JSONCPP_STRING const &msg)
 used internally
 
JSONCPP_NORETURN void throwLogicError (JSONCPP_STRING const &msg)
 used internally
 
JSONCPP_STRING valueToString (LargestInt value)
 
JSONCPP_STRING valueToString (LargestUInt value)
 
JSONCPP_STRING valueToString (Int value)
 
JSONCPP_STRING valueToString (UInt value)
 
JSONCPP_STRING valueToString (double value, unsigned int precision, PrecisionType precisionType)
 
JSONCPP_STRING valueToString (bool value)
 
JSONCPP_STRING valueToQuotedString (const char *value)
 
JSONCPP_STRING 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.
 
JSONCPP_OSTREAM & operator<< (JSONCPP_OSTREAM &, const Value &root)
 Output using the StyledStreamWriter. More...
 
void swap (Value &a, Value &b)
 
bool JSON_API parseFromStream (CharReader::Factory const &, JSONCPP_ISTREAM &, Value *root, std::string *errs)
 
class JSONCPP_DEPRECATED ("Use StreamWriter instead") JSON_API Writer
 Abstract class for writers. More...
 
class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledWriter class JSONCPP_DEPRECATED ("Use StreamWriterBuilder instead") JSON_API StyledStreamWriter
 Outputs a Value in JSON format without formatting (not human friendly). 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

◆ 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 
)

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 '.'.

◆ JSONCPP_DEPRECATED() [1/2]

class Json::JSONCPP_DEPRECATED ( "Use StreamWriter instead"  )

Abstract class for writers.

Deprecated:
Use StreamWriter. (And really, this is an implementation detail.)

◆ JSONCPP_DEPRECATED() [2/2]

class JSONCPP_DEPRECATED ("Use StreamWriterBuilder instead") JSON_API FastWriter class JSONCPP_DEPRECATED ("Use StreamWriterBuilder instead") JSON_API StyledWriter class Json::JSONCPP_DEPRECATED ( "Use StreamWriterBuilder instead"  )

Outputs a Value in JSON format without formatting (not human friendly).

The JSON document is written in a single line. It is not intended for 'human' consumption, but may be useful to support feature such as RPC where bandwidth is limited.

See also
Reader, Value
Deprecated:
Use StreamWriterBuilder.

Writes a Value in JSON format in a human friendly way.

The rules for line break and indent are as follow:

  • Object value:
    • if empty then print {} without indent and line break
    • if not empty the print '{', line break & indent, print one value per line and then unindent and line break and print '}'.
  • Array value:
    • if empty then print [] without indent and line break
    • if the array contains no object value, empty array or some other value types, and all the values fit on one lines, then print the array on a single line.
    • otherwise, it the values do not fit on one line, or the array contains object or non empty array, then print one value per line.

If the Value have comments then they are outputed according to their CommentPlacement.

See also
Reader, Value, Value::setComment()
Deprecated:
Use StreamWriterBuilder.

Writes a Value in JSON format in a human friendly way, to a stream rather than to a string.

The rules for line break and indent are as follow:

  • Object value:
    • if empty then print {} without indent and line break
    • if not empty the print '{', line break & indent, print one value per line and then unindent and line break and print '}'.
  • Array value:
    • if empty then print [] without indent and line break
    • if the array contains no object value, empty array or some other value types, and all the values fit on one lines, then print the array on a single line.
    • otherwise, it the values do not fit on one line, or the array contains object or non empty array, then print one value per line.

If the Value have comments then they are outputed according to their CommentPlacement.

See also
Reader, Value, Value::setComment()
Deprecated:
Use StreamWriterBuilder.
Parameters
indentationEach level will be indented by this amount extra.

Serialize a Value in JSON format.

Parameters
outStream to write to. (Can be ostringstream, e.g.)
rootValue to serialize.
Note
There is no point in deriving from Writer, since write() should not return a value.

◆ operator<<()

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

Output using the StyledStreamWriter.

See also
Json::operator>>()

◆ operator>>()

JSON_API JSONCPP_ISTREAM & Json::operator>> ( JSONCPP_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;
Represents a JSON value.
Definition: atsc_core_utils_json.h:635

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 &  ,
JSONCPP_ISTREAM &  ,
Value root,
std::string *  errs 
)

Consume entire stream and use its begin/end. Someday we might have a real StreamReader, but for now this is convenient.