1 /* 2 * Copyright (c) 2020 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __JSONUTIL_H__ 17 #define __JSONUTIL_H__ 18 19 #include <stdint.h> 20 21 typedef void *json_handle; 22 typedef void *json_pobject; 23 24 json_handle parse_json(const char *data); 25 void free_json(json_handle handle); 26 27 json_pobject get_json_obj(json_pobject parent, const char *field); 28 int32_t get_json_int(json_pobject obj, const char *field); 29 const char *get_json_string(json_pobject obj, const char *field); 30 int32_t get_json_bool(json_pobject obj, const char *field); 31 int32_t get_array_size(json_pobject obj); 32 json_pobject get_array_idx(json_pobject obj, int32_t idx); 33 34 json_pobject create_json_object(void); 35 void delete_json_object(json_pobject obj); 36 void add_item_to_object(json_pobject parent, const char *field, json_pobject obj); 37 json_pobject add_string_to_object(json_pobject parent, const char *field, const char *value); 38 json_pobject add_number_to_object(json_pobject parent, const char *field, int32_t value); 39 json_pobject add_bool_to_object(json_pobject parent, const char *field, int32_t value); 40 json_pobject add_object_to_object(json_pobject parent, const char *field); 41 42 char *json_to_string(json_pobject obj); 43 void free_json_string(char *json_str); 44 45 json_pobject add_array_to_object(json_pobject parent, const char *field); 46 void add_string_to_array(json_pobject objArr, const char *value); 47 void add_number_to_array(json_pobject objArr, int32_t value); 48 void add_bool_to_array(json_pobject objArr, int32_t value); 49 void add_obj_to_array(json_pobject objArr, json_pobject obj); 50 51 #endif /* __JSONUTIL_H__ */ 52