C++ header-only JSON library

Overview

Welcome to taoJSON

Windows CI macOS CI Linux CI Android CI
clang-analyze clang-tidy Sanitizer CodeQL Code Coverage

taoJSON is a C++ header-only JSON library that provides a generic Value Class, uses Type Traits to interoperate with C++ types, uses an Events Interface to convert from and to JSON, JAXN, CBOR, MsgPack and UBJSON, and much more...

Documentation

Warning: The documentation is currently not quite keeping pace with what will hopefully be the last large pre-1.0.0 development burst.

Contact

Join us on Discord

For questions and suggestions regarding taoJSON, success or failure stories, and any other kind of feedback, please feel free to join our Discord server, open a discussion, an issue or a pull request on GitHub or contact the authors at taocpp(at)icemx.net.

Features

  • Supported Standards

    • RFC8259, ECMA-404: The JavaScript Object Notation (JSON) Data Interchange Format.
    • Achieves a 100% conformance score in the Native JSON Benchmark tests.
    • RFC6901: JavaScript Object Notation (JSON) Pointer.
    • RFC6902: JavaScript Object Notation (JSON) Patch.
    • RFC7049: Concise Binary Object Representation (CBOR).
    • JAXN: Relaxed JSON.
    • MsgPack: MessagePack binary format (without extensions).
    • UBJSON: Universal Binary JSON.
  • Value Class

    • JSON data model extended with non-finite number values and binary data.
    • Construction of objects and arrays via std::initializer_list.
    • Conversion from and to arbitrary user-defined types via Type Traits.
    • Built around STL containers std::variant, std::string, std::map, std::vector, etc.
    • No memory allocations by the Value class itself (the wrapped containers allocate normally).
    • Instance sharing for string, binary, Value, and user-defined types via non-owning pointers.
    • C++11 literal operator for Values, including binary data.
    • Optional Base class for Values (e.g. to annotate (sub-)values with file and line).
  • Events Interface

    • Simple, straightforward and flexible Events API.
    • Events-to-Value and Value-to-Events interfaces.
    • Parse JSON & JAXN string representation to Events.
    • Stream Events to (prettified) JSON & JAXN string representation.
    • Conversion from and to binary formats, currently CBOR, UBJSON, MsgPack.
    • Conversion from and to other JSON libraries (e.g. contrib/nlohmann.cpp).
    • Events comparison, hashing, counting, and schema validation.
    • Events Transformers to manipulate Events on-the-fly.

Status

The library is stable as in "works correctly" over months of multiple real-world applications.

The library is not stable as in "under construction"; some parts of the API are under discussion and development and might change and/or be extended before version 1.0.

This library also serves as a real-world example application of the Parsing Expression Grammar Template Library (PEGTL), which is used for parsing the JSON and JAXN representation formats.

Package Managers

You can download and install taoJSON using the Conan package manager:

conan install taocpp-json/1.0.0-beta.11@

The taocpp-json package in conan is kept up to date by Conan team members and community contributors. If the version is out-of-date, please create an issue or pull request on the Conan Center Index repository.

Thank You

The Art of C++

taoJSON is part of The Art of C++.

colinh d-frey uilianries

License

taoJSON is certified Open Source software. It may be used for any purpose, including commercial purposes, at absolutely no cost. It is distributed under the terms of the MIT license reproduced here.

Copyright (c) 2015-2021 Dr. Colin Hirsch and Daniel Frey

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Additional Licenses

taoJSON contains modified portions of the double-conversion library which is licensed as follows:

Copyright 2006-2011, the V8 project authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

taoJSON contains modified portions of James Edward Anhalt III's itoa library which is licensed as follows:

Copyright (c) 2017 James Edward Anhalt III - https://github.com/jeaiii/itoa

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

taoJSON contains modified portions of Ulf Adams' Ryu implementation which is licensed as follows:

Copyright 2018 Ulf Adams

The contents of this file may be used under the terms of the Apache License, Version 2.0.

(See accompanying file LICENSE.ryu or copy at http://www.apache.org/licenses/LICENSE-2.0)

Alternatively, the contents of this file may be used under the terms of the Boost Software License, Version 1.0. (See accompanying file LICENSE-Boost or copy at https://www.boost.org/LICENSE_1_0.txt)

Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

You might also like...
🗄️ single header json parser for C and C++

🗄️ json.h A simple single header solution to parsing JSON in C and C++. JSON is parsed into a read-only, single allocation buffer. The current suppor

single-header json parser for c99 and c++

ghh_json.h a single-header ISO-C99 (and C++ compatible) json loader. why? obviously this isn't the first json library written for C, so why would I wr

A generator of JSON parser & serializer C++ code from structure header files

JSON-CPP-gen This is a program that parses C++ structures from a header file and automatically generates C++ code capable of serializing said structur

A C++17 single-file header-only library to wrap RapidJSON SAX interface

A C++17 single-file header-only library for RapidJSON SAX interface

Lightweight, header-only, C++17 configuration library

uconfig C++ header-only library to parse and emit multi-format configuration for your app. For example, you can parse JSON-file into the config and th

An easy-to-use and competitively fast JSON parsing library for C++17, forked from Bitcoin Cash Node's own UniValue library.

UniValue JSON Library for C++17 (and above) An easy-to-use and competitively fast JSON parsing library for C++17, forked from Bitcoin Cash Node's own

A Haskell library for fast decoding of JSON documents using the simdjson C++ library

hermes A Haskell interface over the simdjson C++ library for decoding JSON documents. Hermes, messenger of the gods, was the maternal great-grandfathe

C library for encoding, decoding and manipulating JSON data

Jansson README Jansson is a C library for encoding, decoding and manipulating JSON data. Its main features and design principles are: Simple and intui

A C++ library for interacting with JSON.

JsonCpp JSON is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value p

Comments
  • Binding questions

    Binding questions

    Hi,

    I have two questions regarding the automatic bindings. I tried to write this:

    #include <tao/json/binding.hpp>
    
    #include "magic_enum.hpp"
    
    
    struct test {
        static int id() {
            return 0;
        }
    };
    
    template<typename T, typename = void>
    struct my_traits
        : public tao::json::traits<T>
    {};
    
    template<>
    struct my_traits<test>
        : public tao::json::binding::object<TAO_JSON_BIND_REQUIRED(magic_enum::enum_name(tao::json::binding::member_kind::required), &test::id)>
    {};
    

    But TAO_JSON_BIND_REQUIRED uses sizeof(), which doesn't work for containers - at least, that seems to be the reason to me. So first question: is there a nearly as nice solution to this? What would you recommend?

    Second question: if the test class has a more complex (non-static) id() method, or if I want to convert the result, is that even possible with the binding syntax, i.e., doing this with a type? Or do I have to do it manually with an assign() implementation?

    question 
    opened by michael-brade 6
  • Schema Validation Failure Reason

    Schema Validation Failure Reason

    I am huge fan of tao-json! Great work! To make tao-json even better it would be super awesome if the schema validation could report more than just true/false, or valid/invalid. Additionally, it could provide the path to the invalid field and a short string explaining the error (something like: expected number) or a error code, like kExpectedNumber.

    enhancement 
    opened by maierlars 0
Releases(1.0.0-beta.13)
  • 1.0.0-beta.13(Sep 23, 2021)

    • The PEGTL is now a submodule (previously there was a copy of the PEGTL configured into namespace tao::json::pegtl).
    • Countless, mostly small, cleanups, extensions and modernisations to the code as well as adding some missing parts.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.12(Dec 23, 2020)

    • Require C++17.
    • Based internal structure on std::variant.
    • Based binary views on std::span (when available) or tao::span (fallback).
    • Finished JAXN parts parser.
    • Fixed compilation with MSVC.
    • Switched CI system to GitHub Actions.
    • Updated embedded taocpp/PEGTL to version 3.1.1.
    • Many small improvements.
    • Many small changes.
    • Many small fixes.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.11(Feb 18, 2018)

    • Completed/fixed support for the binary formats CBOR, MsgPack and UBJSON.
    • Consistent use of traits for construction and comparison.
    • Removed support for storing a nullptr in a type::RAW_PTR node.
    • Added traits for smart pointers and (some) STL containers.
    • Added support for type::OPAQUE_PTR and to generate events from custom values directly.
    • Added optional value annotations via a base class.
    • Reorganized some files/namespaces for binary formats, JAXN.
    • Updated embedded taocpp/PEGTL to version 2.4.0.
    • Created some initial documentation.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.10(Jan 4, 2018)

    • Fixed reversed logic on optional getter.
    • Fixed compile problem with pre-release versions of Clang 6.
    • Updated embedded taocpp/PEGTL to version 2.3.3.
    • Enabled clang-tidy checks in TravisCI build.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.9(Dec 22, 2017)

    • Added support for Visual Studio 2017.
    • Added tao::string_view (which is an alias to std::string_view when available).
    • Added tao::binary_view (which is std::vector<tao::byte>, where tao::byte is an alias to std::byte when available).
    • Added support to store tao::string_view or tao::binary_view.
    • Routed comparison with direct values through the traits class template.
    • Added decoder for the experimental support for UBJSON.
    • Fixed and improved small details all over the place.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.8(Jun 30, 2017)

  • 1.0.0-beta.7(May 19, 2017)

  • 1.0.0-beta.6(Nov 30, 2016)

    • Add experimental support for JSON Reference
    • Add experimental support for JSON Schema
    • Add type/state DISCARDED to catch errors
    • Fix memory leak in some cases if an exception is thrown from a constructor
    • Rename a few enums, methods
    • Performance improvements
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.5(Sep 16, 2016)

    Add SAX consumer and producer for nlohmann/json values. This shows how adaptable and composeable the library is, combining its own powerful parsing, stringify and prettify capabilities with third-party value classes.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.4(Sep 14, 2016)

    Implement SAX API

    • Parse files and string to SAX events
    • Traverse JSON values to produce SAX events
    • Generate a JSON value from SAX events
    • Write SAX events to stream (compact or pretty)

    Use the new SAX classes for parsing files and strings into JSON value and to output JSON string representations. The latter is also faster with the new SAX API compared to the previous solution.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.3(Sep 7, 2016)

    • Add operator[] for (unchecked) indexed access into arrays and objects.
    • Add operator+= and operator-= to add or remove multiple elements from objects.
    • Improve stringify performance by 15%+.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.2(Sep 1, 2016)

    The interface and the code are mostly stable now, only a diff() method (to generate a JSON Patch from two JSON values) and some minor convenience functions will be added before a release candidate.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0-beta.1(Jan 26, 2016)

Owner
The Art of C++
A collection of high-quality C++ libraries
The Art of C++
A very sane (header only) C++14 JSON library

JeayeSON - a very sane C++14 JSON library JeayeSON was designed out of frustration that there aren't many template-based approaches to handling JSON i

Jeaye Wilkerson 128 Nov 28, 2022
C++ header-only JSON library

Welcome to taoJSON taoJSON is a C++ header-only JSON library that provides a generic Value Class, uses Type Traits to interoperate with C++ types, use

The Art of C++ 499 Dec 27, 2022
A small header-only json library in C.

xjson A small header-only json library for C. The "unique" feature is that it allows use of the same code to serialize as well as deserialize, greatly

Stefan Bachmann 23 Jul 19, 2022
json_struct is a single header only C++ library for parsing JSON directly to C++ structs and vice versa

Structurize your JSON json_struct is a single header only library that parses JSON to C++ structs/classes and serializing structs/classes to JSON. It

Jørgen Lind 275 Dec 28, 2022
A small header-only library for converting data between json representation and c++ structs

Table of Contents Table of Contents What Is json_dto? What's new? v.0.3.0 v.0.2.14 v.0.2.13 v.0.2.12 v.0.2.11 v.0.2.10 v.0.2.9 v.0.2.8 v.0.2.7 v.0.2.6

Stiffstream 101 Dec 27, 2022
a header-file-only, JSON parser serializer in C++

PicoJSON - a C++ JSON parser / serializer Copyright © 2009-2010 Cybozu Labs, Inc. Copyright © 2011-2015 Kazuho Oku Licensed under 2-clause BSD license

Kazuho Oku 1k Dec 27, 2022
json-cpp is a C++11 JSON serialization library.

JSON parser and generator for C++ Version 0.1 alpha json-cpp is a C++11 JSON serialization library. Example #include <json-cpp.hpp> struct Foo {

Anatoly Scheglov 7 Oct 30, 2022
This is a JSON C++ library. It can write and read JSON files with ease and speed.

Json Box JSON (JavaScript Object Notation) is a lightweight data-interchange format. Json Box is a C++ library used to read and write JSON with ease a

Anhero inc. 110 Dec 4, 2022
A convenience C++ wrapper library for JSON-Glib providing friendly syntactic sugar for parsing JSON

This library is a wrapper for the json-glib library that aims to provide the user with a trivial alternative API to the API provided by the base json-

Rob J Meijer 17 Oct 19, 2022
json-build is a zero-allocation JSON serializer compatible with C89

json-build is a zero-allocation JSON serializer compatible with C89. It is inspired by jsmn, a minimalistic JSON tokenizer.

Lucas Müller 31 Nov 16, 2022