jsonxx/1.0.1+1

[brief]

A JSON parser in C++

Build Status

Introduction

JSON++ is a light-weight JSON parser, writer and reader written in C++. JSON++ can also convert JSON documents into lossless XML documents.

Contributors

If you've made substantial contribution, please add your link here.

Why another JSON parser?

Perhaps because web service clients are usually written in dynamic languages these days, none of the existing C++ JSON parsers fitted my needs very well, so I wrote one that I used in another project. My goals for JSON++ were:

Other contributors have sinced added more functionalities:

Compiler version

You need a modern C++ compiler. For older compilers, please try legacy branch.

Configuration

Strict/permissive parsing

JSONxx can parse JSON documents both in strict or permissive mode.

When jsonxx::Settings::Parser is set to Strict, JSONxx parser will accept:

When jsonxx::Settings::Parser is set to Permissive, JSONxx parser will accept:

Default value is Permissive.

When jsonxx::Settings::UnquotedKeys is set to Enabled, JSONxx parser will accept:

Default value is Disabled.

Assertions

JSONxx uses internally JSONXX_ASSERT(...) macro that works both in debug and release mode. Set jsonxx::Settings::Assertions value to Disabled to disable assertions.

Default value is Enabled.

Usage

The following snippets are from one of the unit tests. They are quite self-descriptive.

using namespace std;
using namespace jsonxx;

string teststr(
        "{"
        "  \"foo\" : 1,"
        "  \"bar\" : false,"
        "  \"person\" : {\"name\" : \"GWB\", \"age\" : 60,},"
        "  \"data\": [\"abcd\", 42],"
        "}"
);

// Parse string or stream
Object o;
assert(o.parse(teststr));

// Validation. Checking for JSON types and values as well
assert(1 == o.get<Number>("foo"));
assert(o.has<Boolean>("bar"));
assert(o.has<Object>("person"));
assert(o.get<Object>("person").has<Number>("age"));
assert(!o.get<Object>("person").has<Boolean>("old"));
assert(o.get<Object>("person").get<Boolean>("old", false));
assert(o.has<Array>("data"));
assert(o.get<Array>("data").get<Number>(1) == 42);
assert(o.get<Array>("data").get<String>(0) == "abcd");
assert(o.get<Array>("data").get<String>(2, "hello") == "hello");
assert(!o.has<Number>("data"));
cout << o.json() << endl;                     // JSON output
cout << o.xml(JSONx) << endl;                 // JSON to XML conversion (JSONx subtype)
cout << o.xml(JXML) << endl;                  // JSON to XML conversion (JXML subtype)
cout << o.xml(JXMLex) << endl;                // JSON to XML conversion (JXMLex subtype)
// Generate JSON document dynamically
using namespace std;
using namespace jsonxx;
Array a;
a << 123;
a << "hello world";
a << 3.1415;
a << 99.95f;
a << 'h';
a << Object("key", "value");
Object o;
o << "key1" << "value";
o << "key2" << 123;
o << "key3" << a;
cout << o.json() << endl;

To do

version 1.0.1+1
license MIT
repository pkg:cppget.org/stable
location https://pkg.cppget.org/1/stable
download jsonxx-1.0.1+1.tar.gz
sha256 4a8360ac003421bd6fccc8fa270a5477894f391913cf365f7aab0c95e5b815c9
project jsonxx
url github.com/hjiang/jsonxx
package-url github.com/build2-packaging/jsonxx
package-email mjklaim@gmail.com

Builds

toolchain public-0.13.0
config macos_10.15-gcc_9.3_homebrew-static_O3 / x86_64-apple-darwin19.0.0
timestamp 2021-05-12 22:06:52 UTC (02:15:14 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config macos_10.15-gcc_9.3_homebrew-O3 / x86_64-apple-darwin19.0.0
timestamp 2021-05-12 22:05:43 UTC (02:16:24 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config macos_10.15-gcc_9.3_homebrew / x86_64-apple-darwin19.0.0
timestamp 2021-05-12 22:02:22 UTC (02:19:45 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config macos_10.15-clang_11.0 / x86_64-apple-darwin19.0.0
timestamp 2021-05-12 21:59:08 UTC (02:22:58 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config macos_10.15-clang_11.0-static_O3 / x86_64-apple-darwin19.0.0
timestamp 2021-05-12 21:56:40 UTC (02:25:26 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config macos_10.15-clang_11.0-O3 / x86_64-apple-darwin19.0.0
timestamp 2021-05-12 21:55:14 UTC (02:26:53 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config macos_10.14-clang_10.0 / x86_64-apple-darwin18.6.0
timestamp 2021-05-12 21:46:37 UTC (02:35:30 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-msvc_16.6-static_O2 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 18:23:12 UTC (05:58:55 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-msvc_16.6 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 18:21:58 UTC (06:00:09 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-clang_10.0_llvm_msvc_16.6-static_O2 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 18:20:26 UTC (06:01:40 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-clang_10.0_llvm_msvc_16.6-O2 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 18:19:09 UTC (06:02:58 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-msvc_16.6-O2 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 18:17:45 UTC (06:04:21 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-gcc_9.2_mingw_w64-static_O3 / x86_64-w64-mingw32
timestamp 2021-05-12 18:17:15 UTC (06:04:52 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-gcc_9.2_mingw_w64-O3 / x86_64-w64-mingw32
timestamp 2021-05-12 18:14:11 UTC (06:07:56 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-clang_9.0_llvm_msvc_16.4 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 18:10:48 UTC (06:11:19 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-gcc_9.2_mingw_w64 / x86_64-w64-mingw32
timestamp 2021-05-12 18:09:42 UTC (06:12:24 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-clang_10.0_llvm_msvc_16.6 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 18:06:41 UTC (06:15:26 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-clang_10.0_msvc_msvc_16.6 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 18:04:41 UTC (06:17:26 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10_devmode-msvc_16.4 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 17:56:29 UTC (06:25:38 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-clang_10.0_libc++-static_O3 / x86_64-linux-gnu
timestamp 2021-05-12 17:54:32 UTC (06:27:34 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-clang_10.0_libc++-O3 / x86_64-linux-gnu
timestamp 2021-05-12 17:50:23 UTC (06:31:44 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-clang_10.0_libc++ / x86_64-linux-gnu
timestamp 2021-05-12 17:48:16 UTC (06:33:51 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-clang_10.0-static_O3 / x86_64-linux-gnu
timestamp 2021-05-12 17:47:54 UTC (06:34:12 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-msvc_16.5 / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 17:45:20 UTC (06:36:47 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-clang_10.0-O3 / x86_64-linux-gnu
timestamp 2021-05-12 17:42:54 UTC (06:39:12 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config freebsd_12-clang_8.0-static_O3 / x86_64-freebsd12.1
timestamp 2021-05-12 17:38:33 UTC (06:43:33 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-clang_10.0 / x86_64-linux-gnu
timestamp 2021-05-12 17:36:38 UTC (06:45:29 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-gcc_10.1-static_O3 / x86_64-linux-gnu
timestamp 2021-05-12 17:36:28 UTC (06:45:38 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config freebsd_12-clang_8.0-O3 / x86_64-freebsd12.1
timestamp 2021-05-12 17:36:17 UTC (06:45:49 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-clang_9.0_libc++ / x86_64-linux-gnu
timestamp 2021-05-12 17:35:49 UTC (06:46:18 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-gcc_10.1-O3 / x86_64-linux-gnu
timestamp 2021-05-12 17:33:59 UTC (06:48:08 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config freebsd_12-clang_8.0 / x86_64-freebsd12.1
timestamp 2021-05-12 17:26:45 UTC (06:55:21 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-gcc_10.1 / x86_64-linux-gnu
timestamp 2021-05-12 17:26:09 UTC (06:55:57 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-clang_9.0 / x86_64-linux-gnu
timestamp 2021-05-12 17:25:58 UTC (06:56:08 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config freebsd_12-clang_6.0 / x86_64-freebsd12.0
timestamp 2021-05-12 17:24:52 UTC (06:57:15 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config linux_debian_10-gcc_9.3 / x86_64-linux-gnu
timestamp 2021-05-12 17:21:09 UTC (07:00:57 hours ago)
result success | log | rebuild
toolchain public-0.13.0
config windows_10-clang_10.0_llvm_msvc_16.6_lld / x86_64-microsoft-win32-msvc14.2
timestamp 2021-05-12 10:09:42 UTC (14:12:24 hours ago)
result error (test-installed) | log | rebuild