JsoNeat
Some JSON parse/iterate C++ classes build on top of Jsmn
Loading...
Searching...
No Matches
jsoneat.hh File Reference

helper class to iterate the JSMN token array and extract data More...

#include "jsmn/jsmn.h"
#include <iterator>
#include <type_traits>
#include <cstddef>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <string>
Include dependency graph for jsoneat.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  jsoneat::JsoNeat< input_type >
 Parse JSON into tokens and iterate over it. Will handle all allocations. More...
 
class  jsoneat::JsoNeat< input_type >::Iterator
 This has iterator functionality, but also provides lots of token related member functions. More...
 
class  jsoneat::JsoNeat_fs< JSON_MAX_TOKENS, input_type >
 Parse JSON into fixed size token array. More...
 
struct  jsoneat::KvPair< D >
 pair of a reference and a json-key More...
 

Macros

#define _JSONEAT_COUNT_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...)   N
 
#define _JSONEAT_COUNT(...)   _JSONEAT_COUNT_N( __VA_ARGS__, 10, 9, 8, 7, 6, 5 ,4, 3, 2, 1)
 
#define _JSONEAT_BUILD_CHAIN_1(_1)   _JSONEAT_KvPairs_ACT(_1)
 
#define _JSONEAT_BUILD_CHAIN_2(_1, ...)   _JSONEAT_KvPairs_ACT(_1) , _JSONEAT_BUILD_CHAIN_1(__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN_3(_1, ...)   _JSONEAT_KvPairs_ACT(_1) , _JSONEAT_BUILD_CHAIN_2(__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN_4(_1, ...)   _JSONEAT_KvPairs_ACT(_1) , _JSONEAT_BUILD_CHAIN_3(__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN_5(_1, ...)   _JSONEAT_KvPairs_ACT(_1) , _JSONEAT_BUILD_CHAIN_4(__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN_6(_1, ...)   _JSONEAT_KvPairs_ACT(_1) , _JSONEAT_BUILD_CHAIN_5(__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN_7(_1, ...)   _JSONEAT_KvPairs_ACT(_1) , _JSONEAT_BUILD_CHAIN_6(__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN_8(_1, ...)   _JSONEAT_KvPairs_ACT(_1) , _JSONEAT_BUILD_CHAIN_7(__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN_9(_1, ...)   _JSONEAT_KvPairs_ACT(_1) , _JSONEAT_BUILD_CHAIN_8(__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN_10(_1, ...)   _JSONEAT_KvPairs_ACT(_1) , _JSONEAT_BUILD_CHAIN_9(__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN_INC(CT, ...)   _JSONEAT_BUILD_CHAIN_ ## CT (__VA_ARGS__)
 
#define _JSONEAT_BUILD_CHAIN(CT, ...)   _JSONEAT_BUILD_CHAIN_INC(CT, __VA_ARGS__)
 
#define _JSONEAT_KvPairs_ACT(x)   jsoneat::KvPair(#x, x)
 
#define JSONEAT_KvPairs(...)   _JSONEAT_BUILD_CHAIN( _JSONEAT_COUNT(__VA_ARGS__), __VA_ARGS__)
 Create argument list of jsoneat::KvPair-pairs, each containg a data-member reference and the corrosponding JSON key with the same name as the data-member \args list of all data-members to be de-serialized.
 

Typedefs

using jsoneat::JsonNeat_cp = JsoNeat< char * >
 working on non-const char JSON. this allows null terminating strings in place with get_value_as_string
 
using jsoneat::JsonNeat_ccp = JsoNeat< const char * >
 working on const char JSON.
 

Functions

template<int MaxTokens = 32, typename T , typename S >
bool jsoneat::from_json_member (T &obj, S json)
 convenient function template to de-serialize from a JSON string (FIXME: should not be in this header)
 

Detailed Description

helper class to iterate the JSMN token array and extract data

Author
Bert Winkelmann (github.com/zwiebert)

Function Documentation

◆ from_json_member()

template<int MaxTokens = 32, typename T , typename S >
bool jsoneat::from_json_member ( T &  obj,
json 
)

convenient function template to de-serialize from a JSON string (FIXME: should not be in this header)

Template Parameters
SType of JSON string like char *, const char *, std::string, ...
TType of object. The object has to have a from_json(jsmn_iter) member function template
MaxTokensfixed size of JSMN token array (allocated on stack)
Parameters
jsonJSON string
Returns
success