Architecture — cJSON Qualification

Requirement: The cJSON parser implements a recursive-descent algorithm operating on a UTF-8 byte stream. Control flow passes through tokenizer, value parser, and object/array constructors. ARCH_PARSER_FLOW
Requirement: The cJSON printer traverses an in-memory cJSON object graph, emitting formatted or unformatted JSON text through a bounded output buffer. ARCH_PRINTER_FLOW
status: active
tags: architecture, printing
Requirement: Memory management uses the standard C malloc/free allocator by default, with an optional hook mechanism (cJSON_InitHooks) that allows integration with a safety-qualified memory allocator. ARCH_MEMORY_MODEL
status: active
tags: architecture, memory
links outgoing: REQ_CJSON_MEMORY_SAFE
links incoming: REQ_CJSON_MEMORY_SAFE
Requirement: The cJSON data model is a tagged union (cJSON struct) supporting six value types: null, boolean, number, string, array, object. Arrays are linked lists of cJSON items; objects are linked lists of cJSON items with associated string keys. ARCH_DATA_MODEL
status: active
tags: architecture, datamodel
Requirement: The cJSON module boundary is defined by cJSON.h. All public API functions are marked CJSON_PUBLIC. Internal helpers (parse_, print_, ensure_, etc.) are static and not part of the external interface. The cJSON_Utils extension provides JSON Patch and JSON Pointer operations on top of the core API. ARCH_MODULE_BOUNDARY

Component Architecture (PlantUML)

cJSON v1.7.19 Component Architecture Diagram

Requirement: Component Decomposition — cJSON Core and Utils ARCH_COMPONENT_DECOMPOSITION
status: active
tags: architecture, decomposition

The cJSON core (cJSON.c) contains four subsystems:

  • Parser: recursive-descent JSON tokenizer and value constructor

  • Printer: tree-walk JSON serializer to buffer

  • Memory Management: malloc/free with optional hook replacement

  • Object Model: tagged-union cJSON struct with linked-list children for arrays/objects

The cJSON Utils (cJSON_Utils.c) builds on the core with JSON Patch (RFC 6902), JSON Pointer (RFC 6901), and Sort/Merge utilities.

All components interface with the C standard library for string and memory operations.

Parser Flow (PlantUML)

cJSON Parser Flow Sequence Diagram

Data Model (PlantUML)

cJSON Data Model Class Diagram

Safety Architecture — Freedom from Interference

Requirement: Freedom from Interference Measures ARCH_FFI_MEASURES
status: active
tags: architecture, ffi, safety

FFI measures in cJSON:

  • No global state — all state is in caller-owned cJSON* objects

  • Memory allocation hooks enable replacement with a qualified allocator

  • Bounded stack depth via CJSON_NESTING_LIMIT (default 1000)

  • No thread synchronization performed inside the library

Integrator responsibilities:

  • Provide a qualified allocator via cJSON_InitHooks

  • Validate all inputs before API calls

  • Check all return values for error indicators

  • Handle error paths at the integration boundary

  • Ensure inputs respect nesting limits