summaryrefslogtreecommitdiff
path: root/lib/json.h
blob: 7f624b9b8ce5cd8ca5e752dceffbf449813317dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * json.h
 *
 * See the README file for copyright information and how to reach the author.
 *
 */

#pragma once

//***************************************************************************
// Include
//***************************************************************************

#ifdef USEJSON

#include <jansson.h>

#include "db.h"
#include "common.h"

//***************************************************************************
// JSON Helper Functions
//***************************************************************************

int json2Data(json_t* obj, MemoryStruct* data, const char* encoding = 0);

int addFieldToJson(json_t* obj, cDbTable* table, const char* fname, int ignoreEmpty = yes, const char* extName = 0);
int addFieldToJson(json_t* obj, cDbValue* value, int ignoreEmpty = yes, const char* extName = 0);
int getFieldFromJson(json_t* obj, cDbRow* row, const char* fname, const char* extName = 0);

int jStringValid(const char* s);

const char* getStringFromJson(json_t* obj, const char* name, const char* def = 0);
int getIntFromJson(json_t* obj, const char* name, int def = na);
int getBoolFromJson(json_t* obj, const char* name, bool def = false);
long getLongFromJson(json_t* obj, const char* name, long def = na);
double getDoubleFromJson(json_t* obj, const char* name, double def = na);

int addToJson(json_t* obj, const char* name, const char* value, const char* def = "");
int addToJson(json_t* obj, const char* name, long value);
int addToJson(json_t* obj, const char* name, json_t* o);

#endif // USEJSON