|
| JSON (Class type) |
|
| JSON (std::initializer_list< JSON > list) |
|
| JSON (JSON &&other) |
|
JSON & | operator= (JSON &&other) |
|
| JSON (const JSON &other) |
|
JSON & | operator= (const JSON &other) |
|
template<typename T > |
| JSON (T b, typename std::enable_if< std::is_same< T, bool >::value >::type *=0) |
|
template<typename T > |
| JSON (T i, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, bool >::value >::type *=0) |
|
template<typename T > |
| JSON (T f, typename std::enable_if< std::is_floating_point< T >::value >::type *=0) |
|
template<typename T > |
| JSON (T s, typename std::enable_if< std::is_convertible< T, std::string >::value >::type *=0) |
|
| JSON (std::nullptr_t) |
|
template<typename T > |
void | append (T arg) |
|
template<typename T , typename... U> |
void | append (T arg, U... args) |
|
template<typename T > |
std::enable_if< std::is_same< T, bool >::value, JSON & >::type | operator= (T b) |
|
template<typename T > |
std::enable_if< std::is_integral< T >::value &&!std::is_same< T, bool >::value, JSON & >::type | operator= (T i) |
|
template<typename T > |
std::enable_if< std::is_floating_point< T >::value, JSON & >::type | operator= (T f) |
|
template<typename T > |
std::enable_if< std::is_convertible< T, std::string >::value, JSON & >::type | operator= (T s) |
|
JSON & | operator[] (const std::string &key) |
|
JSON & | operator[] (unsigned index) |
|
JSON & | at (const std::string &key) |
|
const JSON & | at (const std::string &key) const |
|
JSON & | at (unsigned index) |
|
const JSON & | at (unsigned index) const |
|
std::size_t | length () const |
|
bool | hasKey (const std::string &key) const |
|
std::size_t | size () const |
|
Class | JSONType () const |
|
bool | IsNull () const |
|
bool | IsArray () const |
|
bool | IsBoolean () const |
|
bool | IsFloating () const |
|
bool | IsIntegral () const |
|
bool | IsString () const |
|
bool | IsObject () const |
|
std::string | ToString (std::error_code &ec) const noexcept |
|
std::string | ToString () const |
|
std::string | ToUnescapedString (std::error_code &ec) const noexcept |
|
std::string | ToUnescapedString () const |
|
double | ToFloat (std::error_code &ec) const noexcept |
|
double | ToFloat () const |
|
long long | ToInt (std::error_code &ec) const noexcept |
|
long long | ToInt () const |
|
bool | ToBool (std::error_code &ec) const noexcept |
|
bool | ToBool () const |
|
JSONWrapper< std::map< std::string, JSON > > | ObjectRange () |
|
JSONWrapper< std::deque< JSON > > | ArrayRange () |
|
JSONConstWrapper< std::map< std::string, JSON > > | ObjectRange () const |
|
JSONConstWrapper< std::deque< JSON > > | ArrayRange () const |
|
std::string | dump (int depth=1, std::string tab=" ") const |
|
std::string | dumpMinified () const |
|
Class to represent and use JSON objects. Class may throw exceptions of type std::error_code on error.
Example Usage:
Array Example
Example to show how to use Arrays.
#include <iostream>
int main()
{
JSON array;
array[2] = "Test2";
cout << array << endl;
array[1] = "Test1";
cout << array << endl;
array[0] = "Test0";
cout << array << endl;
array[3] = "Test4";
cout << array << endl;
JSON Array2;
Array2[2][0][1] = true;
cout << Array2 << endl;
}
Lightweight JSON library for exporting/importing data in JSON format from/to C++. Can be used standal...
Class to represent and use JSON objects. Class may throw exceptions of type std::error_code on error.
Definition: JSON.h:445
Initialization Example
Simple example which shows how to directly load an object.
#include <iostream>
#include <cstddef>
int main()
{
JSON obj( {
"Key", 1,
"Key3", true,
"Key4", nullptr,
"Key2", {
"Key4", "VALUE",
"Arr", giri::json::Array( 1, "Str", false )
}
} );
cout << obj << endl;
}
Iterator Example
This example shows how to iterate over stored arrays and objects.
#include <iostream>
void dumpArrayConst( const JSON &array ) {
for( auto &j : array.ArrayRange() )
std::cout << "Value: " << j << "\n";
}
void dumpArray( JSON &array ) {
for( auto &j : array.ArrayRange() )
std::cout << "Value: " << j << "\n";
}
void dumpObjectConst( const JSON &object ) {
std::cout << "Object[ " << j.first << " ] = " << j.second << "\n";
}
void dumpObject( JSON &object ) {
std::cout << "Object[ " << j.first << " ] = " << j.second << "\n";
}
int main()
{
array[0] = "Test0";
array[1] = "Test1";
array[2] = "Test2";
array[3] = "Test3";
obj[ "Key0" ] = "Value1";
obj[ "Key1" ] = array;
obj[ "Key2" ] = 123;
std::cout << "=============== tests ================\n";
dumpArray( array );
dumpObject( obj );
std::cout << "============ const tests =============\n";
dumpArrayConst( array );
dumpObjectConst( obj );
}
JSONWrapper< std::map< std::string, JSON > > ObjectRange()
Definition: JSON.h:1027
static JSON Make(Class type)
Definition: JSON.h:609
Datatypes Example
In this example it is shown, how to store all supported datatypes within an JSON object.
#include <iostream>
int main()
{
JSON null;
JSON Bool( true );
JSON Str( "RawString" );
JSON Str2( string( "C++String" ) );
JSON Int( 1 );
JSON Float( 1.2 );
JSON Arr = giri::json::Array();
JSON Obj = giri::json::Object();
Bool = false;
Bool = "rtew";
Bool = 1;
Bool = 1.1;
Bool = string( "asd" );
Arr.append( 1 );
Arr.append( "test" );
Arr.append( false );
JSON& val = Arr[0];
JSON Arr2 = giri::json::Array( 2, "Test", true );
Obj["Key1"] = 1.0;
Obj["Key2"] = "Value";
JSON Obj2 = giri::json::Object();
Obj2["Key3"] = 1;
Obj2["Key4"] = Arr;
Obj2["Key5"] = Arr2;
Obj["Key6"] = Obj2;
cout << Obj << endl;
JSON Obj3 = {
"Key1", "Value",
"Key2", true,
"Key3", {
"Key4", giri::json::Array( "This", "Is", "An", "Array" ),
"Key5", {
"BooleanValue", true
}
}
};
cout << Obj3 << endl;
}
Load string Example
This example shows how to load an object from string.
#include <iostream>
int main()
{
JSON EscStr =
JSON::Load(
"\" \\\"Some\\/thing\\\" \"" );
JSON Arr =
JSON::Load(
"[1,2, true, false,\"STRING\", 1.5]" );
JSON Obj =
JSON::Load(
"{ \"Key\" : \"StringValue\","
" \"Key2\" : true, "
" \"Key3\" : 1234, "
" \"Key4\" : null }" );
cout << Int << endl;
cout << Float << endl;
cout << Str << endl;
cout << EscStr << endl;
cout << Arr << endl;
cout << Obj << endl;
}
static JSON Load(const std::string &str)
Definition: JSON.h:1421
Assignment of primitives Example
Assign and print primitives.
#include <iostream>
#include <ios>
int main()
{
JSON obj;
obj = true;
cout << "Value: " << boolalpha << obj.ToBool() << endl;
obj = "Test String";
cout << "Value: " << obj.ToString() << endl;
obj = 2.2;
cout << "Value: " << obj.ToFloat() << endl;
obj = 3;
cout << "Value: " << obj.ToInt() << endl;
}