Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_json.c File Reference

Implementation of the small public JSON wrapper over cJSON. More...

#include "nilorea/n_json.h"
#include "nilorea/n_log.h"
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
#include "nilorea/n_str.h"
Include dependency graph for n_json.c:

Go to the source code of this file.

Macros

#define AS_CJSON(p)
#define AS_CONST_CJSON(p)
#define AS_NJSON(p)

Functions

N_JSON * n_json_array_at (const N_JSON *arr, size_t i)
 Get an array element by index.
size_t n_json_array_size (const N_JSON *arr)
 Number of elements in an array node.
const char * n_json_as_string (const N_JSON *v, const char *dflt)
 Get the string value of a node itself (e.g.
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.
void n_json_free (N_JSON **root)
 Free a JSON tree and NULL the caller's pointer.
N_JSON * n_json_get (const N_JSON *obj, const char *key)
 Get a child member of an object by key (case-sensitive).
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.
int n_json_is_array (const N_JSON *v)
 Report whether a node is a JSON array.
int n_json_is_object (const N_JSON *v)
 Report whether a node is a JSON object.
N_JSON * n_json_parse (const char *text)
 Parse a JSON document from a NUL-terminated string.
N_JSON * n_json_parse_file (const char *path)
 Parse a JSON document from a file.
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.
char * n_json_string_dup (const N_JSON *obj, const char *key)
 Duplicate a string member (caller frees), or NULL when absent.

Detailed Description

Implementation of the small public JSON wrapper over cJSON.

Author
Castagnier Mickael
Version
1.0
Date
2024

Definition in file n_json.c.

Macro Definition Documentation

◆ AS_CJSON

#define AS_CJSON ( p)
Value:
((cJSON*)(void*)(p))

Definition at line 39 of file n_json.c.

Referenced by n_json_free().

◆ AS_CONST_CJSON

#define AS_CONST_CJSON ( p)
Value:
((const cJSON*)(const void*)(p))

Definition at line 40 of file n_json.c.

Referenced by n_json_array_at(), n_json_array_size(), n_json_as_string(), n_json_bool(), n_json_get(), n_json_int(), n_json_is_array(), n_json_is_object(), and n_json_string().

◆ AS_NJSON

#define AS_NJSON ( p)
Value:
((N_JSON*)(void*)(p))
struct N_JSON N_JSON
Opaque JSON node (a cJSON node under the hood).
Definition n_json.h:48

Definition at line 41 of file n_json.c.

Referenced by n_json_array_at(), n_json_get(), n_json_parse(), and n_json_parse_file().