json test

Embed: (wiki syntax)

« Back to documentation index

Json Namespace Reference

Json Namespace Reference

JSON (JavaScript Object Notation). More...

Namespaces

namespace  anonymous_namespace{json_writer.cpp}

Data Structures

class  Features
 Configuration passed to reader and writer. More...
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  RuntimeError
 Exceptions which the user cannot easily avoid. More...
class  LogicError
 Exceptions thrown by JSON_ASSERT/JSON_FAIL macros. More...
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  StreamWriter
 Usage: More...
class  StreamWriterBuilder
 Build a StreamWriter implementation. More...

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

Functions

class JSONCPP_DEPRECATED ("Use CharReader and CharReaderBuilder instead") JSON_API Reader
 Unserialize a JSON document into a Value.
bool JSON_API parseFromStream (CharReader::Factory const &, JSONCPP_ISTREAM &, Value *root, std::string *errs)
 Consume entire stream and use its begin/end.
JSON_API JSONCPP_ISTREAM & operator>> (JSONCPP_ISTREAM &, Value &)
 Read from 'sin' into 'root'.
JSONCPP_NORETURN void throwRuntimeError (JSONCPP_STRING const &msg)
 used internally
JSONCPP_NORETURN void throwLogicError (JSONCPP_STRING const &msg)
 used internally
JSONCPP_STRING JSON_API writeString (StreamWriter::Factory const &factory, Value const &root)
 Write into stringstream, then return string, for convenience.
class JSONCPP_DEPRECATED ("Use StreamWriter instead") JSON_API Writer
 Abstract class for writers.
class JSONCPP_DEPRECATED ("Use StreamWriterBuilder instead") JSON_API FastWriter
 Outputs a Value in JSON format without formatting (not human friendly).
JSON_API JSONCPP_OSTREAM & operator<< (JSONCPP_OSTREAM &, const Value &root)
 Output using the StyledStreamWriter.
static JSONCPP_STRING codePointToUTF8 (unsigned int cp)
 Converts a unicode code-point to UTF-8.
static void uintToString (LargestUInt value, char *&current)
 Converts an unsigned integer to string.
static void fixNumericLocale (char *begin, char *end)
 Change ',' to '.
static char * duplicateStringValue (const char *value, size_t length)
 Duplicates the specified string value.
static void releasePrefixedStringValue (char *value)
 Free the string duplicated by duplicateStringValue()/duplicateAndPrefixStringValue().

Detailed Description

JSON (JavaScript Object Notation).


Enumeration Type Documentation

anonymous enum
Enumerator:
uintToStringBufferSize 

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

Definition at line 65 of file json_tool.h.

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)

Definition at line 104 of file value.h.

enum 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).

Definition at line 93 of file value.h.


Function Documentation

static JSONCPP_STRING Json::codePointToUTF8 ( unsigned int  cp ) [static]

Converts a unicode code-point to UTF-8.

Definition at line 37 of file json_tool.h.

static char* Json::duplicateStringValue ( const char *  value,
size_t  length 
) [static]

Duplicates the specified string value.

Parameters:
valuePointer to the string to duplicate. Must be zero-terminated if length is "unknown".
lengthLength of the value. if equals to unknown, then it will be computed using strlen(value).
Returns:
Pointer on the duplicate instance of string.

Definition at line 97 of file json_value.cpp.

static void Json::fixNumericLocale ( char *  begin,
char *  end 
) [static]

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

Definition at line 92 of file json_tool.h.

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

Abstract class for writers.

Definition at line 143 of file writer.h.

class JSONCPP_DEPRECATED ( "Use StreamWriterBuilder instead"   )

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

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

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

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

See also:
Reader, Value

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

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

Drop the "null" string from the writer's output for nullValues. Strictly speaking, this is not valid JSON. But when the output is being fed to a browser's JavaScript, it makes for smaller output and the browser can handle the output just fine.

Serialize a Value in JSON format.

Parameters:
rootValue to serialize.
Returns:
String containing the JSON document that represents the root value.
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.

Serialize a Value in JSON format.

Parameters:
rootValue to serialize.
Returns:
String containing the JSON document that represents the root value.
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.

Definition at line 163 of file writer.h.

class Json::JSONCPP_DEPRECATED ( "Use CharReader and CharReaderBuilder instead"   )

Unserialize a JSON document into a Value.

An error tagged with where in the JSON text it was encountered.

The offsets give the [start, limit) range of bytes within the text. Note that this is bytes, not codepoints.

Constructs a Reader allowing all features for parsing.

Constructs a Reader allowing the specified feature set for parsing.

Read a Value from a JSON document.

Parameters:
documentUTF-8 encoded string containing the document to read.
root[out] Contains the root value of the document if it was successfully parsed.
collectCommentstrue to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if Features::allowComments_ is false.
Returns:
true if the document was successfully parsed, false if an error occurred.

Read a Value from a JSON document.

Parameters:
beginDocPointer on the beginning of the UTF-8 encoded string of the document to read.
endDocPointer on the end of the UTF-8 encoded string of the document to read. Must be >= beginDoc.
root[out] Contains the root value of the document if it was successfully parsed.
collectCommentstrue to collect comment and allow writing them back during serialization, false to discard comments. This parameter is ignored if Features::allowComments_ is false.
Returns:
true if the document was successfully parsed, false if an error occurred.

Parse from input stream.

See also:
Json::operator>>(std::istream&, Json::Value&).

Returns a user friendly string that list errors in the parsed document.

Returns:
Formatted error message with the list of errors with their location in the parsed document. An empty string is returned if no error occurred during parsing.

Returns a user friendly string that list errors in the parsed document.

Returns:
Formatted error message with the list of errors with their location in the parsed document. An empty string is returned if no error occurred during parsing.

Returns a vector of structured erros encounted while parsing.

Returns:
A (possibly empty) vector of StructuredError objects. Currently only one error can be returned, but the caller should tolerate multiple errors. This can occur if the parser recovers from a non-fatal parse error and then encounters additional errors.

Add a semantic error message.

Parameters:
valueJSON Value location associated with the error
messageThe error message.
Returns:
true if the error was successfully added, false if the Value offset exceeds the document size.

Add a semantic error message with extra context.

Parameters:
valueJSON Value location associated with the error
messageThe error message.
extraAdditional JSON Value location to contextualize the error
Returns:
true if the error was successfully added, false if either Value offset exceeds the document size.

Return whether there are any errors.

Returns:
true if there are no errors to report false if errors have occurred.

Definition at line 35 of file reader.h.

JSONCPP_OSTREAM & operator<< ( JSONCPP_OSTREAM &  sout,
const Value &  root 
)

Output using the StyledStreamWriter.

See also:
Json::operator>>()

Definition at line 1226 of file json_writer.cpp.

JSONCPP_ISTREAM & operator>> ( JSONCPP_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:

 Json::Value root;
 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<<()

Definition at line 2052 of file json_reader.cpp.

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.

static void releasePrefixedStringValue ( char *  value ) [static]

Free the string duplicated by duplicateStringValue()/duplicateAndPrefixStringValue().

Definition at line 154 of file json_value.cpp.

JSONCPP_NORETURN void throwLogicError ( JSONCPP_STRING const &  msg )

used internally

Definition at line 212 of file json_value.cpp.

JSONCPP_NORETURN void throwRuntimeError ( JSONCPP_STRING const &  msg )

used internally

Definition at line 208 of file json_value.cpp.

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

Converts an unsigned integer to string.

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

Definition at line 79 of file json_tool.h.

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.

Definition at line 1219 of file json_writer.cpp.