Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_json.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
33#ifndef __N_JSON_H
34#define __N_JSON_H
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#include <stddef.h>
41
48typedef struct N_JSON N_JSON;
49
53N_JSON* n_json_parse(const char* text);
54
58N_JSON* n_json_parse_file(const char* path);
59
62void n_json_free(N_JSON** root);
63
68N_JSON* n_json_get(const N_JSON* obj, const char* key);
69
75const char* n_json_string(const N_JSON* obj, const char* key, const char* dflt);
76
81char* n_json_string_dup(const N_JSON* obj, const char* key);
82
88long n_json_int(const N_JSON* obj, const char* key, long dflt);
89
95int n_json_bool(const N_JSON* obj, const char* key, int dflt);
96
100int n_json_is_array(const N_JSON* v);
101
105int n_json_is_object(const N_JSON* v);
106
110size_t n_json_array_size(const N_JSON* arr);
111
116N_JSON* n_json_array_at(const N_JSON* arr, size_t i);
117
122const char* n_json_as_string(const N_JSON* v, const char* dflt);
123
126#ifdef __cplusplus
127}
128#endif
129
130#endif /* __N_JSON_H */
char * key
N_JSON * n_json_parse(const char *text)
Parse a JSON document from a NUL-terminated string.
Definition n_json.c:43
N_JSON * n_json_array_at(const N_JSON *arr, size_t i)
Get an array element by index.
Definition n_json.c:118
const char * n_json_as_string(const N_JSON *v, const char *dflt)
Get the string value of a node itself (e.g.
Definition n_json.c:124
char * n_json_string_dup(const N_JSON *obj, const char *key)
Duplicate a string member (caller frees), or NULL when absent.
Definition n_json.c:85
size_t n_json_array_size(const N_JSON *arr)
Number of elements in an array node.
Definition n_json.c:112
long n_json_int(const N_JSON *obj, const char *key, long dflt)
Get a numeric member as a long, or a default when absent/not a number.
Definition n_json.c:90
const char * n_json_string(const N_JSON *obj, const char *key, const char *dflt)
Get a string member, or a default when absent/not a string.
Definition n_json.c:78
int n_json_bool(const N_JSON *obj, const char *key, int dflt)
Get a boolean member, or a default when absent/not a boolean.
Definition n_json.c:97
int n_json_is_object(const N_JSON *v)
Report whether a node is a JSON object.
Definition n_json.c:108
void n_json_free(N_JSON **root)
Free a JSON tree and NULL the caller's pointer.
Definition n_json.c:65
struct N_JSON N_JSON
Opaque JSON node (a cJSON node under the hood).
Definition n_json.h:48
N_JSON * n_json_parse_file(const char *path)
Parse a JSON document from a file.
Definition n_json.c:49
int n_json_is_array(const N_JSON *v)
Report whether a node is a JSON array.
Definition n_json.c:104
N_JSON * n_json_get(const N_JSON *obj, const char *key)
Get a child member of an object by key (case-sensitive).
Definition n_json.c:72