GRASS 8 Programmer's Manual  8.5.0dev(2025)-a92a3a018a
gjson.c
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * MODULE: GRASS json output interface
4  *
5  * AUTHOR: Nishant Bansal (nishant.bansal.282003@gmail.com)
6  *
7  * PURPOSE: parson library function wrapper
8  * part of the gjson library
9  *
10  * COPYRIGHT: (C) 2024 by the GRASS Development Team
11  *
12  * This program is free software under the GNU General Public
13  * License (>=v2). Read the file COPYING that comes with GRASS
14  * for details.
15  *
16  *****************************************************************************/
17 
18 #include "gjson.h"
19 #include "parson.h"
20 
21 typedef struct json_object_t G_json_object_t;
22 typedef struct json_array_t G_json_array_t;
23 typedef struct json_value_t G_json_value_t;
24 
25 /* *************************************************************** */
26 /* ***** WRAPPER FOR PARSON FUNCTIONS USED IN GRASS ************** */
27 /* *************************************************************** */
28 
30 {
32 }
33 
35 {
37 }
38 
40 {
41  return json_value_get_type((const JSON_Value *)value);
42 }
43 
45 {
46  return (G_JSON_Object *)json_value_get_object((const JSON_Value *)value);
47 }
48 
50 {
51  return (G_JSON_Object *)json_object((const JSON_Value *)value);
52 }
53 
55  const char *name)
56 {
57  return (G_JSON_Object *)json_object_get_object((const JSON_Object *)object,
58  name);
59 }
60 
62  const char *name)
63 {
64  return (G_JSON_Array *)json_object_get_array((const JSON_Object *)object,
65  name);
66 }
67 
69  const char *name)
70 {
71  return (G_JSON_Value *)json_object_get_value((const JSON_Object *)object,
72  name);
73 }
74 
75 const char *G_json_object_get_string(const G_JSON_Object *object,
76  const char *name)
77 {
78  return json_object_get_string((const JSON_Object *)object, name);
79 }
80 
81 double G_json_object_get_number(const G_JSON_Object *object, const char *name)
82 {
83  return json_object_get_number((const JSON_Object *)object, name);
84 }
85 
86 int G_json_object_get_boolean(const G_JSON_Object *object, const char *name)
87 {
88  return json_object_get_boolean((const JSON_Object *)object, name);
89 }
90 
92 {
94  (const JSON_Object *)object);
95 }
97  G_JSON_Value *value)
98 {
99  return json_object_set_value((JSON_Object *)object, name,
100  (JSON_Value *)value);
101 }
103  const char *string)
104 {
105  return json_object_set_string((JSON_Object *)object, name, string);
106 }
108  double number)
109 {
110  return json_object_set_number((JSON_Object *)object, name, number);
111 }
113  int boolean)
114 {
115  return json_object_set_boolean((JSON_Object *)object, name, boolean);
116 }
117 
119 {
120  return json_object_set_null((JSON_Object *)object, name);
121 }
122 
124  const char *name, const char *string)
125 {
126  return json_object_dotset_string((JSON_Object *)object, name, string);
127 }
128 
129 const char *G_json_object_dotget_string(G_JSON_Object *object, const char *name)
130 {
131  return json_object_dotget_string((JSON_Object *)object, name);
132 }
133 
135  const char *name, double number)
136 {
137  return json_object_dotset_number((JSON_Object *)object, name, number);
138 }
139 
140 double G_json_object_dotget_number(G_JSON_Object *object, const char *name)
141 {
142  return json_object_dotget_number((JSON_Object *)object, name);
143 }
144 
146 {
147  return json_object_dotset_null((JSON_Object *)object, name);
148 }
149 
151 {
152  return (G_JSON_Array *)json_array((const JSON_Value *)value);
153 }
154 
156 {
157  return (G_JSON_Value *)json_array_get_value((const JSON_Array *)array,
158  index);
159 }
160 
161 const char *G_json_array_get_string(const G_JSON_Array *array, size_t index)
162 {
163  return json_array_get_string((const JSON_Array *)array, index);
164 }
165 
166 double G_json_array_get_number(const G_JSON_Array *array, size_t index)
167 {
168  return json_array_get_number((const JSON_Array *)array, index);
169 }
170 
171 int G_json_array_get_boolean(const G_JSON_Array *array, size_t index)
172 {
173  return json_array_get_boolean((const JSON_Array *)array, index);
174 }
175 
177  G_JSON_Value *value)
178 {
179  return json_array_append_value((JSON_Array *)array, (JSON_Value *)value);
180 }
181 
183  const char *string)
184 {
185  return json_array_append_string((JSON_Array *)array, string);
186 }
187 
189 {
190  return json_array_append_number((JSON_Array *)array, number);
191 }
192 
194 {
195  return json_array_append_boolean((JSON_Array *)array, boolean);
196 }
197 
199 {
200  return json_array_append_null((JSON_Array *)array);
201 }
202 
204 {
206 }
207 
209 {
210  return json_serialize_to_string_pretty((const JSON_Value *)value);
211 }
212 
214 {
216 }
217 
219 {
220  json_value_free((JSON_Value *)value);
221 }
G_JSON_Status G_json_array_append_boolean(G_JSON_Array *array, int boolean)
Definition: gjson.c:193
struct json_value_t G_json_value_t
Definition: gjson.c:23
G_JSON_Status G_json_object_set_number(G_JSON_Object *object, const char *name, double number)
Definition: gjson.c:107
G_JSON_Status G_json_object_set_null(G_JSON_Object *object, const char *name)
Definition: gjson.c:118
G_JSON_Status G_json_array_append_null(G_JSON_Array *array)
Definition: gjson.c:198
void G_json_value_free(G_JSON_Value *value)
Definition: gjson.c:218
G_JSON_Status G_json_object_dotset_null(G_JSON_Object *object, const char *name)
Definition: gjson.c:145
G_JSON_Status G_json_object_set_value(G_JSON_Object *object, const char *name, G_JSON_Value *value)
Definition: gjson.c:96
int G_json_object_get_boolean(const G_JSON_Object *object, const char *name)
Definition: gjson.c:86
G_JSON_Status G_json_object_dotset_number(G_JSON_Object *object, const char *name, double number)
Definition: gjson.c:134
G_JSON_Status G_json_object_dotset_string(G_JSON_Object *object, const char *name, const char *string)
Definition: gjson.c:123
G_JSON_Status G_json_object_set_boolean(G_JSON_Object *object, const char *name, int boolean)
Definition: gjson.c:112
G_JSON_Status G_json_array_append_number(G_JSON_Array *array, double number)
Definition: gjson.c:188
void G_json_free_serialized_string(char *string)
Definition: gjson.c:213
const char * G_json_object_get_string(const G_JSON_Object *object, const char *name)
Definition: gjson.c:75
double G_json_array_get_number(const G_JSON_Array *array, size_t index)
Definition: gjson.c:166
G_JSON_Value * G_json_value_init_object(void)
Definition: gjson.c:29
int G_json_array_get_boolean(const G_JSON_Array *array, size_t index)
Definition: gjson.c:171
G_JSON_Object * G_json_object_get_object(const G_JSON_Object *object, const char *name)
Definition: gjson.c:54
G_JSON_Object * G_json_object(const G_JSON_Value *value)
Definition: gjson.c:49
G_JSON_Value * G_json_object_get_value(const G_JSON_Object *object, const char *name)
Definition: gjson.c:68
G_JSON_Value_Type G_json_value_get_type(const G_JSON_Value *value)
Definition: gjson.c:39
G_JSON_Object * G_json_value_get_object(const G_JSON_Value *value)
Definition: gjson.c:44
double G_json_object_get_number(const G_JSON_Object *object, const char *name)
Definition: gjson.c:81
double G_json_object_dotget_number(G_JSON_Object *object, const char *name)
Definition: gjson.c:140
G_JSON_Status G_json_object_set_string(G_JSON_Object *object, const char *name, const char *string)
Definition: gjson.c:102
char * G_json_serialize_to_string_pretty(const G_JSON_Value *value)
Definition: gjson.c:208
G_JSON_Array * G_json_object_get_array(const G_JSON_Object *object, const char *name)
Definition: gjson.c:61
struct json_object_t G_json_object_t
Definition: gjson.c:21
const char * G_json_array_get_string(const G_JSON_Array *array, size_t index)
Definition: gjson.c:161
G_JSON_Status G_json_array_append_string(G_JSON_Array *array, const char *string)
Definition: gjson.c:182
G_JSON_Value * G_json_value_init_array(void)
Definition: gjson.c:34
G_JSON_Value * G_json_object_get_wrapping_value(const G_JSON_Object *object)
Definition: gjson.c:91
G_JSON_Array * G_json_array(const G_JSON_Value *value)
Definition: gjson.c:150
const char * G_json_object_dotget_string(G_JSON_Object *object, const char *name)
Definition: gjson.c:129
struct json_array_t G_json_array_t
Definition: gjson.c:22
void G_json_set_float_serialization_format(const char *format)
Definition: gjson.c:203
G_JSON_Status G_json_array_append_value(G_JSON_Array *array, G_JSON_Value *value)
Definition: gjson.c:176
G_JSON_Value * G_json_array_get_value(const G_JSON_Array *array, size_t index)
Definition: gjson.c:155
struct G_json_array_t G_JSON_Array
Definition: gjson.h:11
struct G_json_object_t G_JSON_Object
Definition: gjson.h:10
struct G_json_value_t G_JSON_Value
Definition: gjson.h:12
int G_JSON_Status
Definition: gjson.h:26
int G_JSON_Value_Type
Definition: gjson.h:23
const char * name
Definition: named_colr.c:6
JSON_Status json_object_dotset_string(JSON_Object *object, const char *name, const char *string)
Definition: parson.c:2559
int json_object_get_boolean(const JSON_Object *object, const char *name)
Definition: parson.c:1660
JSON_Value * json_value_init_array(void)
Definition: parson.c:1901
JSON_Value * json_array_get_value(const JSON_Array *array, size_t index)
Definition: parson.c:1765
JSON_Status json_array_append_null(JSON_Array *array)
Definition: parson.c:2391
JSON_Object * json_value_get_object(const JSON_Value *value)
Definition: parson.c:1822
JSON_Status json_array_append_boolean(JSON_Array *array, int boolean)
Definition: parson.c:2378
JSON_Value * json_object_get_value(const JSON_Object *object, const char *name)
Definition: parson.c:1627
JSON_Status json_object_dotset_null(JSON_Object *object, const char *name)
Definition: parson.c:2616
JSON_Status json_object_set_number(JSON_Object *object, const char *name, double number)
Definition: parson.c:2473
void json_set_float_serialization_format(const char *format)
Definition: parson.c:2841
double json_array_get_number(const JSON_Array *array, size_t index)
Definition: parson.c:1783
const char * json_array_get_string(const JSON_Array *array, size_t index)
Definition: parson.c:1773
JSON_Status json_object_set_string(JSON_Object *object, const char *name, const char *string)
Definition: parson.c:2450
JSON_Status json_object_set_boolean(JSON_Object *object, const char *name, int boolean)
Definition: parson.c:2484
void json_free_serialized_string(char *string)
Definition: parson.c:2217
JSON_Object * json_object_get_object(const JSON_Object *object, const char *name)
Definition: parson.c:1650
JSON_Value * json_object_get_wrapping_value(const JSON_Object *object)
Definition: parson.c:1732
char * json_serialize_to_string_pretty(const JSON_Value *value)
Definition: parson.c:2196
JSON_Status json_array_append_value(JSON_Array *array, JSON_Value *value)
Definition: parson.c:2330
JSON_Object * json_object(const JSON_Value *value)
Definition: parson.c:2799
JSON_Value * json_value_init_object(void)
Definition: parson.c:1885
int json_array_get_boolean(const JSON_Array *array, size_t index)
Definition: parson.c:1798
JSON_Status json_object_set_value(JSON_Object *object, const char *name, JSON_Value *value)
Definition: parson.c:2404
void json_value_free(JSON_Value *value)
Definition: parson.c:1867
JSON_Status json_object_set_null(JSON_Object *object, const char *name)
Definition: parson.c:2495
JSON_Array * json_object_get_array(const JSON_Object *object, const char *name)
Definition: parson.c:1655
const char * json_object_dotget_string(const JSON_Object *object, const char *name)
Definition: parson.c:1677
JSON_Status json_array_append_string(JSON_Array *array, const char *string)
Definition: parson.c:2338
const char * json_object_get_string(const JSON_Object *object, const char *name)
Definition: parson.c:1635
double json_object_get_number(const JSON_Object *object, const char *name)
Definition: parson.c:1645
double json_object_dotget_number(const JSON_Object *object, const char *name)
Definition: parson.c:1689
JSON_Value_Type json_value_get_type(const JSON_Value *value)
Definition: parson.c:1817
JSON_Array * json_array(const JSON_Value *value)
Definition: parson.c:2804
JSON_Status json_object_dotset_number(JSON_Object *object, const char *name, double number)
Definition: parson.c:2588
JSON_Status json_array_append_number(JSON_Array *array, double number)
Definition: parson.c:2365
struct json_array_t JSON_Array
Definition: parson.h:46
struct json_value_t JSON_Value
Definition: parson.h:47
struct json_object_t JSON_Object
Definition: parson.h:45