DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
json.cpp File Reference

Implementation of the zero-heap JSON writer and top-level reader. More...

#include "json.h"
#include "shared_primitives/numparse.h"
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Enumerations

enum class  JsonEsc { LITERAL_C , EMITTED , TRUNCATED }
 

Functions

bool json_get_str (const char *json, const char *key, char *out, size_t out_cap)
 Read a top-level string member from a JSON object body.
 
bool json_get_int (const char *json, const char *key, long *out)
 Read a top-level integer member from a JSON object body.
 
bool json_get_bool (const char *json, const char *key, bool *out)
 Read a top-level boolean member (true/false) from a JSON object body.
 

Detailed Description

Implementation of the zero-heap JSON writer and top-level reader.

Definition in file json.cpp.

Enumeration Type Documentation

◆ JsonEsc

enum class JsonEsc
strong
Enumerator
LITERAL_C 
EMITTED 
TRUNCATED 

Definition at line 371 of file json.cpp.

Function Documentation

◆ json_get_str()

bool json_get_str ( const char *  json,
const char *  key,
char *  out,
size_t  out_cap 
)

Read a top-level string member from a JSON object body.

Finds "key": "..." at the root object level (nested objects/arrays and string contents are skipped, so a same-named nested key is not matched), unescapes the value, and copies it (NUL-terminated, bounded by out_cap) into out.

Parameters
jsonNUL-terminated JSON object text.
keyMember name to find.
outDestination buffer.
out_capCapacity of out including the NUL.
Returns
true if a string member was found and copied; false otherwise.

Definition at line 512 of file json.cpp.

References EMITTED, and TRUNCATED.

◆ json_get_int()

bool json_get_int ( const char *  json,
const char *  key,
long *  out 
)

Read a top-level integer member from a JSON object body.

Returns
true if the member exists and parses as an integer; false otherwise.

Definition at line 552 of file json.cpp.

References det_strtol().

◆ json_get_bool()

bool json_get_bool ( const char *  json,
const char *  key,
bool *  out 
)

Read a top-level boolean member (true/false) from a JSON object body.

Returns
true if the member exists and is a JSON boolean; false otherwise.

Definition at line 567 of file json.cpp.