Similar to C++ streams, but the stream elements are structured JSON data rather than characters.

JIOS : JSON Input Output Streams

Similar to C++ streams, but the stream elements are structured JSON data rather than characters.

Contents

  • Features
  • [Parsing Examples](#Parsing Examples)
  • [Printing Examples](#Printing Examples)
  • Dependencies
  • [Other Libraries](#Other Libraries)

Features

Incremental Streamed Parsing

Not all parsing of JSON has to happen at once, but rather parsing can be streamed before all JSON is available. This is similar to many SAX parsers, but with jios client code still calls jios and "pulls" data rather than being called like a SAX parser would.

Document Object Model (DOM) friendliness

JSON objects and arrays are represented by distinct C++ types and can be "walked" and iterated in for loops like a DOM interface.

Non-blocking Parsing of Asynchronous Data Sources

jios can be called assuming all data is available or the expecting method can be called to check whether jios is still expecting more data. This can be used in asynchronous code to determine parsing should performed later when more data is available.

Async Example

Parse Directly Into Strongly-types Data Structures

Source back-end do not have to construct entire json objects in memory and instead data can read data incrementally into custom strongly types C++ objects.

A template library (express.hpp) is included which makes it easy to declare the JSON object members to bind to C++ class members so that such C++ classes can immediately be read and written as JSON.

Expression Example

Interoperable with standard C++ streams

Three ways jios interoperates with C++ streams:

  • included back-end source and sink and read and write with C++ streams.
  • C++ types and have insertion (<<) and extraction (>>) defined for C++ streams automatically work with jios. This mechanism can be overloaded when C++ types should be represented as structures JSON rather than JSON strings.
  • The jios front-end provides syntactic sugar and semantics that are like C++ streams.

Separate Independent Back-ends

Streams are backed by source and sink back-ends which do not have to operate on textual JSON.

Interoperability with Google Protocol Buffers

C++ classes generated by Google Protocol Buffers are automatically readable and writable to any jios sources and sinks.

Parsing Examples

> i >> s >> j; ">
  istringstream ss("1 \"two\" 3");
  int i, j;
  string s;
  json_in(ss) >> i >> s >> j;

Use any type with the istream >> (extraction) operator defined

> t1 >> t2; cout << boolalpha << bool(t1 == seconds(63)) << ' ' << bool(t2 == seconds(12)) << endl; ">
  using namespace boost::posix_time;
  istringstream ss("[\"00:01:03\", \"00:00:12\"]");
  time_duration t1, t2;
  ijarray ija = json_in(ss).get().array();
  ija >> t1 >> t2;
  cout << boolalpha << bool(t1 == seconds(63)) << ' '
                    << bool(t2 == seconds(12)) << endl;

outputs

  true true

Parse JSON arrays into standard containers

many; json_in(ss) >> many; list expect = {1, 2, 3}; cout << boolalpha << bool(many == expect) << endl; outputs ">
  istringstream ss("[1, 2, 3]");
  list<int> many;
  json_in(ss) >> many;
  list<int> expect = {1, 2, 3};
  cout << boolalpha << bool(many == expect) << endl;
outputs

true


### Iterate on JSON streams and arrays

```cpp
  istringstream ss("1 2 3 4 5");
  int sum = 0;
  for (ijvalue & v : json_in(ss)) {
    int i;
    if (v.read(i)) {
      sum += i;
    }
  }
  cout << sum << endl;

outputs

  15

JSON arrays are parsed as a stream and accessible incrementally

> i; cout << i << endl; ss << ", 2 "; ija >> i; cout << i << endl; ss << "]"; if (ija.at_end()) { cout << "Done!" << endl; } ">
  stringstream ss;
  int i = 0;
  ss << "[";
  ijarray ija = json_in(ss).get().array();
  ss << "1 ";
  ija >> i;
  cout << i << endl;
  ss << ", 2 ";
  ija >> i;
  cout << i << endl;
  ss << "]";
  if (ija.at_end()) { cout << "Done!" << endl; }

outputs

  1
  2
  Done!

Iterate by name value pair on JSON objects

  stringstream ss;
  ss << R"( { "a":1, "b":2, "c":3 } )";
  int sum = 0;
  for (ijpair & nv : json_in(ss).get().object()) {
    int i;
    if (nv.read(i)) {
      sum += i;
    }
  }
  cout << sum << endl;

outputs

  6

Parse JSON object as stream of name value pairs

> tie(name1, age1) >> tie(name2, age2); cout << name1 << " is " << age1 - age2 << " years older than " << name2 << endl; ">
  stringstream ss;
  ss << R"( { "Joe":35, "Jane":33 } )";
  string name1, name2;
  int age1, age2;
  ijobject ijo = json_in(ss).get().object();
  ijo >> tie(name1, age1) >> tie(name2, age2);
  cout << name1 << " is " << age1 - age2 << " years older than "
       << name2 << endl;

outputs

  Joe is 2 years older than Jane 

Printing Examples

  jios::json_out(std::cout, '\n') << 1 << 2 << "three";

outputs

  1
  2
  "three"

In the rest of the examples assume

  using namespace std;
  using namespace jios;
  ojstream jout = json_out(cout);

JSON Arrays

  ojarray oja = jout.put().array();
  for (int i = 0; i < 3; ++i) {
    oja << i;
  }
  oja << endj;

outputs

  [0, 1, 2]

JSON Objects

  string b = "BEE";
  jout.put().object() << make_pair("one", 1) << tie("two", b) << endj;

outputs

  {"one":1, "two":"BEE"}

Use any type with the ostream << (insertion) operator defined

  using namespace boost::posix_time;
  jout.put().array() << seconds(3) << seconds(2) << seconds(1) << endj;

outputs

  ["00:00:03", "00:00:02", "00:00:01"]

Even use such types as JSON object keys.

  using namespace boost::posix_time;
  jout.put().object() << make_pair(seconds(3), "launch")
                      << make_pair(seconds(7), "explode") << endj;

outputs

  {"00:00:03":"launch", "00:00:07":"explode"}

Dependencies

  • C++11
  • boost
  • JSON-C
  • Google Protocol Buffers (optional)

Other Libraries

There are many C/C++ JSON libraries. www.json.org has a long list of such C and C++ libraries.

A few worth mentioning are

Owner
Similar Resources

A general purpose data serializer.

GPDS is a General Purpose Data Serializer implemented as a very small C++ library. It allows to serialize C++ classes to and from XML files in a gener

Dec 2, 2022

Protocol Buffers - Google's data interchange format

Protocol Buffers - Google's data interchange format Copyright 2008 Google Inc. https://developers.google.com/protocol-buffers/ Overview Protocol Buffe

Jan 3, 2023

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON

JSONCONS jsoncons is a C++, header-only library for constructing JSON and JSON-like data formats such as CBOR. For each supported data format, it enab

Jan 4, 2023

An optimized "RTOS" (more than HAL but less than RTOS) for ROV controling and getting sensor data

Nitori-ROV-OS 一个专门为水下机器人(ROV、AUV)进行优化的实时操作系统,暂命名为 Nitori,中文名 荷取 可以通过修改硬件兼容层(Port)进行移植 预计最初版本支持stm32f407和stm32h750,并在实验室目前的水下机器人中进行部署 系统分为四层,六个主要组件: 硬件

Jan 10, 2022

https://github.com/json-c/json-c is the official code repository for json-c. See the wiki for release tarballs for download. API docs at http://json-c.github.io/json-c/

\mainpage json-c Overview and Build Status Building on Unix Prerequisites Build commands CMake options Testing Building with vcpkg Linking to libjson-

Dec 31, 2022

Arbitrary Precision provides C++ long integer types that behave as basic integer types. This library aims to be intuitive and versatile in usage, rather than fast.

Arbitrary Precision (AP) Cross-platform and cross-standard header-only arbitrary precision arithmetic library. Currently it offers integer types that

Sep 28, 2022

✔️The smallest header-only GUI library(4 KLOC) for all platforms

✔️The smallest header-only GUI library(4 KLOC) for all platforms

Welcome to GUI-lite The smallest header-only GUI library (4 KLOC) for all platforms. 中文 Lightweight ✂️ Small: 4,000+ lines of C++ code, zero dependenc

Jan 8, 2023

An OBS plugin that allows capture of independant application audio streams on Windows, in a similar fashion to OBS's game capture and Discord's application streaming.

An OBS plugin that allows capture of independant application audio streams on Windows, in a similar fashion to OBS's game capture and Discord's application streaming.

win-capture-audio An OBS plugin based on OBS's win-capture/game-capture that hooks WASAPI's audio output functions (rather than the various graphics A

Jan 9, 2023

HashLibPlus is a recommended C++11 hashing library that provides a fluent interface for computing hashes and checksums of strings, files, streams, bytearrays and untyped data to mention but a few.

HashLibPlus HashLibPlus is a recommended C++11 hashing library that provides a fluent interface for computing hashes and checksums of strings, files,

Dec 22, 2022

This repo does not contain any skins that work by themselves, but rather addons to already existing skins like CakeOS and Polybar

This repo does not contain any skins that work by themselves, but rather addons to already existing skins like CakeOS and Polybar

Rainmeter-addons ⚠ This repo does not contain any skins that work by themselves, but rather addons to already existing skins like CakeOS and Polybar E

Nov 3, 2022

This library support run-time type casting faster than dynamic_cast ( similar to unreal engine's CastTo )

This library support run-time type casting faster than dynamic_cast ( similar to unreal engine's CastTo )

Fast Runtime Type Casting This library give you C++ Fast Runtime Type Casting faster than dynamic_cast ( similar to Unreal Engine's CastTo, IsChildOf

Jun 11, 2022

Upgraded from Pixar postcard path tracing, instead of printing Pixar, this program print my name, which pose to be more challenging than the original code. The upgraded is also more readable and run 9x faster than the original source code.

Upgraded from Pixar postcard path tracing, instead of printing Pixar, this program print my name, which pose to be more challenging than the original code. The upgraded is also more readable and run 9x faster than the original source code.

SDF-Sphere-Tracing Upgraded from Pixar postcard path tracing, instead of printing Pixar, this program print my name, which pose to be more challenging

Dec 29, 2022

JSON Input Output Streams

JIOS : JSON Input Output Streams Similar to C++ streams, but the stream elements are structured JSON data rather than characters. Contents Features [P

Aug 16, 2019

A C++ data container replicating std::stack functionality but with better performance than standard library containers in a stack context.

plf::stack A data container replicating std::stack functionality but with better performance than standard library containers in a stack context. C++9

Sep 11, 2022

Code and Data for our CVPR 2021 paper "Structured Scene Memory for Vision-Language Navigation"

SSM-VLN Code and Data for our CVPR 2021 paper "Structured Scene Memory for Vision-Language Navigation". Environment Installation Download Room-to-Room

Dec 3, 2022

A software C library designed to extract data attributes from network packets, server logs, and from structured events in general, in order to make them available for analysis

MMT-DPI A software C library desinged to extract data attributes from network packets, server logs, and from structured events in general, in odrder t

Nov 9, 2022
Comments
  • enable way to avoid optional<T> jios_read overload when T not default constructible

    enable way to avoid optional jios_read overload when T not default constructible

    When a type is not default constructible then optional jios_read is overloaded, but really normal T jios_read should get overloaded plus some kind of "pre-jios_read emplace pseudo-default" init of optional should be possible to overload.

  • enable jios_stringify/jios_unstringify overloading capability

    enable jios_stringify/jios_unstringify overloading capability

    Currently istream/ostream extraction/insertion is used for any type other than std::string for keys.

    A system similar to jios_read/jios_write could be enables whereby jios_stringify/jios_unstringify functions can be overloaded for custom types to control exactly how types parsed or printed as strings in JSON keys or string values.

  • add ijvalue::map() alternative to ijvalue::object()

    add ijvalue::map() alternative to ijvalue::object()

    ijvalue::map() should return a map-like type which provides random key access to JSON-like objects in contrast to ijvalue::object which provides a range-like type for sequential only access

Dec 31, 2022
The bit level data interchange format for serializing data structures.

bitproto Bitproto is a fast, lightweight and easy-to-use bit level data interchange format for serializing data structures. Website: https://bitproto.

Jan 3, 2023
JSON for Modern C++
JSON for Modern C++

Design goals Sponsors Integration CMake Package Managers Pkg-config Examples JSON as first-class data type Serialization / Deserialization STL-like ac

Dec 30, 2022
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

Jan 4, 2023
Parsing gigabytes of JSON per second
Parsing gigabytes of JSON per second

simdjson : Parsing gigabytes of JSON per second JSON is everywhere on the Internet. Servers spend a *lot* of time parsing it. We need a fresh approach

Jan 2, 2023
A C++11 or library for parsing and serializing JSON to and from a DOM container in memory.
A C++11 or library for parsing and serializing JSON to and from a DOM container in memory.

Branch master develop Azure Docs Drone Matrix Fuzzing --- Appveyor codecov.io Boost.JSON Overview Boost.JSON is a portable C++ library which provides

Dec 29, 2022
Header-only library for automatic (de)serialization of C++ types to/from JSON.

fuser 1-file header-only library for automatic (de)serialization of C++ types to/from JSON. how it works The library has a predefined set of (de)seria

Dec 17, 2022
Yet another JSON/YAML/BSON serialization library for C++.
Yet another JSON/YAML/BSON serialization library for C++.

ThorsSerializer Support for Json Yaml Bson NEW Benchmark Results Conformance mac linux Performance max linux For details see: JsonBenchmark Yet anothe

Dec 10, 2022
Protocol Buffers - Google's data interchange format

Protocol Buffers - Google's data interchange format Copyright 2008 Google Inc. https://developers.google.com/protocol-buffers/ Overview Protocol Buffe

Dec 29, 2022