Midas C++ API - mjson (JSON documents)
This page contains the full API reference for mjson (mjson/mjson.h), the C++ library that midas uses for JSON documents. A JSON document is held as a tree of MJsonNode objects, which you can parse from text, build up, read and write out as text.
JSON-RPC methods written in C++ receive their parameters, and build their replies, as MJsonNode objects. See RPC (rpc_xxx, JSON-RPC).
The ODB can be saved in JSON format. See ODB: programming.
mjson/mjson.h
Classes
MJsonNode
Defined in mjson/mjson.h:36
Methods
AddToArray
void AddToArray(MJsonNode* node)
public "put" methods
Declared in mjson/mjson.h:76, defined in mjson/mjson.cxx:958
AddToObject
void AddToObject(const char* name, MJsonNode* node)
add node to an array. the array takes ownership of this node
add node to an object
Declared in mjson/mjson.h:77, defined in mjson/mjson.cxx:968
Copy
const
MJsonNode*Copy() const
dump the subtree to standard output
Declared in mjson/mjson.h:99, defined in mjson/mjson.cxx:1201
DeleteObjectNode
void DeleteObjectNode(const char* name)
add node to an object. the object takes ownership of this node
Declared in mjson/mjson.h:80, defined in mjson/mjson.cxx:1020
Dump
const
void Dump(int nest = 0) const
return node type as string
Declared in mjson/mjson.h:98, defined in mjson/mjson.cxx:1154
Encode
static
static std::string Encode(const char* s)
string encoder
Declared in mjson/mjson.h:58, defined in mjson/mjson.cxx:737
EncodeDouble
static
static std::string EncodeDouble(double v)
Declared in mjson/mjson.h:60, defined in mjson/mjson.cxx:776
EncodeLL
static
static std::string EncodeLL(long long v)
Declared in mjson/mjson.h:59, defined in mjson/mjson.cxx:769
FindObjectNode
const
const MJsonNode*FindObjectNode(const char* name) const
get array of object subnodes, NULL if not object, empty array if value is JSON "null"
Declared in mjson/mjson.h:87, defined in mjson/mjson.cxx:1009
GetArray
const
const MJsonNodeVector*GetArray() const
get node type: MJSON_xxx
Declared in mjson/mjson.h:84, defined in mjson/mjson.cxx:985
GetArrayBuffer
const
void GetArrayBuffer(const char** pptr, size_t* psize) const
get boolean value, false if not a boolean or value is JSON "null"
Declared in mjson/mjson.h:93, defined in mjson/mjson.cxx:1095
GetBool
const
bool GetBool() const
get number or integer value, 0 if not a number or value is JSON "null"
get boolean value, false if not a boolean or value is JSON "null"
Declared in mjson/mjson.h:92, defined in mjson/mjson.cxx:1087
GetDouble
const
double GetDouble() const
get 64-bit long long value, 0 if not an integer or value is JSON "null"
Declared in mjson/mjson.h:91, defined in mjson/mjson.cxx:1061
GetError
const
std::string GetError() const
Declared in mjson/mjson.h:94, defined in mjson/mjson.cxx:1117
GetInt
const
long long GetInt() const
get string value, "" if not string or value is JSON "null"
Declared in mjson/mjson.h:89, defined in mjson/mjson.cxx:1045
GetLL
const
long long GetLL() const
get integer value, 0 if not an integer or value is JSON "null"
Declared in mjson/mjson.h:90, defined in mjson/mjson.cxx:1053
GetObjectNames
const
const MJsonStringVector*GetObjectNames() const
get array value, NULL if not array, empty array if value is JSON "null"
Declared in mjson/mjson.h:85, defined in mjson/mjson.cxx:993
GetObjectNodes
const
const MJsonNodeVector*GetObjectNodes() const
get array of object names, NULL if not object, empty array if value is JSON "null"
Declared in mjson/mjson.h:86, defined in mjson/mjson.cxx:1001
GetString
const
std::string GetString() const
find subnode with given name, NULL if not object, NULL is name not found
Declared in mjson/mjson.h:88, defined in mjson/mjson.cxx:1037
GetType
const
int GetType() const
delete a node from an object
get node type: MJSON_xxx
Declared in mjson/mjson.h:83, defined in mjson/mjson.cxx:980
MakeArray
static
static MJsonNode*MakeArray()
public factory constructors
Declared in mjson/mjson.h:63, defined in mjson/mjson.cxx:887
MakeArrayBuffer
Note: this method has 2 different signatures.
MakeArrayBuffer
static
static MJsonNode*MakeArrayBuffer(char* ptr, size_t size)
Declared in mjson/mjson.h:71, defined in mjson/mjson.cxx:940
MakeArrayBuffer
static
static MJsonNode*MakeArrayBuffer(std::vector<char>* buf)
the node takes ownership of the buffer
Declared in mjson/mjson.h:72, defined in mjson/mjson.cxx:949
MakeBool
static
static MJsonNode*MakeBool(bool value)
Declared in mjson/mjson.h:68, defined in mjson/mjson.cxx:918
MakeError
static
static MJsonNode*MakeError(MJsonNode* errornode, const char* errormessage, const char* sin, const char* serror)
the node takes ownership of the buffer
Declared in mjson/mjson.h:73, defined in mjson/mjson.cxx:850
MakeInt
static
static MJsonNode*MakeInt(long long value)
Declared in mjson/mjson.h:66, defined in mjson/mjson.cxx:904
MakeJSON
static
static MJsonNode*MakeJSON(const char* json)
Declared in mjson/mjson.h:70, defined in mjson/mjson.cxx:933
MakeNull
static
static MJsonNode*MakeNull()
Declared in mjson/mjson.h:69, defined in mjson/mjson.cxx:928
MakeNumber
static
static MJsonNode*MakeNumber(double value)
Declared in mjson/mjson.h:67, defined in mjson/mjson.cxx:911
MakeObject
static
static MJsonNode*MakeObject()
Declared in mjson/mjson.h:64, defined in mjson/mjson.cxx:892
MakeString
static
static MJsonNode*MakeString(const char* value)
Declared in mjson/mjson.h:65, defined in mjson/mjson.cxx:897
MJsonNode
protected
MJsonNode(int type)
make a copy of the json tree
Declared in mjson/mjson.h:102, defined in mjson/mjson.cxx:1125
Parse
static
static MJsonNode*Parse(const char* jsonstring)
parser
Declared in mjson/mjson.h:52, defined in mjson/mjson.cxx:696
Stringify
const
std::string Stringify(int flags = 0) const
encoder
Declared in mjson/mjson.h:55, defined in mjson/mjson.cxx:795
TypeToString
static
static const char*TypeToString(int type)
get error message from MJSON_ERROR nodes
Declared in mjson/mjson.h:97, defined in mjson/mjson.cxx:1130
~MJsonNode
~MJsonNode()
dtor
Declared in mjson/mjson.h:49, defined in mjson/mjson.cxx:702
Attributes
arraybuffer_ptr
protected
char* arraybuffer_ptr = NULL
Defined in mjson/mjson.h:45
arraybuffer_size
protected
size_t arraybuffer_size = 0
Defined in mjson/mjson.h:44
arraybuffer_vec
protected
std::vector<char>* arraybuffer_vec = NULL
Defined in mjson/mjson.h:46
double_value
protected
double double_value = 0
Defined in mjson/mjson.h:43
ll_value
protected
long long ll_value = 0
Defined in mjson/mjson.h:42
object_names
protected
MJsonStringVector object_names
Defined in mjson/mjson.h:40
string_value
protected
std::string string_value
Defined in mjson/mjson.h:41
subnodes
protected
MJsonNodeVector subnodes
Defined in mjson/mjson.h:39
type
protected
int type
Defined in mjson/mjson.h:38
Type definitions
MJsonNodeVector
typedef std::vector<MJsonNode*> MJsonNodeVector
Defined in mjson/mjson.h:34
MJsonStringVector
typedef std::vector<std::string> MJsonStringVector
Defined in mjson/mjson.h:33
Macros
MJSON_ARRAY
#define MJSON_ARRAY 1
Defined in mjson/mjson.h:21
MJSON_ARRAYBUFFER
#define MJSON_ARRAYBUFFER 9
Defined in mjson/mjson.h:29
MJSON_BOOL
#define MJSON_BOOL 6
Defined in mjson/mjson.h:26
MJSON_ERROR
#define MJSON_ERROR -1
Defined in mjson/mjson.h:19
MJSON_INT
#define MJSON_INT 4
Defined in mjson/mjson.h:24
MJSON_JSON
#define MJSON_JSON 8
Defined in mjson/mjson.h:28
MJSON_NONE
#define MJSON_NONE 0
Defined in mjson/mjson.h:20
MJSON_NULL
#define MJSON_NULL 7
Defined in mjson/mjson.h:27
MJSON_NUMBER
#define MJSON_NUMBER 5
Defined in mjson/mjson.h:25
MJSON_OBJECT
#define MJSON_OBJECT 2
Defined in mjson/mjson.h:22
MJSON_STRING
#define MJSON_STRING 3
Defined in mjson/mjson.h:23