--- title: "JSON Utilities" description: "Utility functions for parsing JSON data in embedded applications" keywords: ["JSON", "ArduinoJson", "parsing", "ESP32", "embedded"] --- ## JSON Utilities **Path**: [`src/utils/json_utils.h`](../../src/utils/json_utils.h) **Revision History**: - Initial documentation A collection of inline utility functions for parsing JSON data in embedded applications. These functions provide a consistent way to extract values from JSON objects, with built-in type validation and error reporting. ## REQUIREMENTS - ArduinoJson library - ArduinoLog library ## PROVIDES - `JsonUtils` namespace containing utility functions: - `parseJsonFieldUint32`: Parses a 32-bit unsigned integer from JSON - `parseJsonFieldUint8`: Parses an 8-bit unsigned integer from JSON - `parseJsonFieldBool`: Parses a boolean value from JSON ## FEATURES - Type validation for JSON field parsing - Maintains default values when fields are missing or of incorrect type - Debug logging for parsing errors - Consistent parsing interface across different data types ## DEPENDENCIES - [ArduinoJson](https://arduinojson.org/) - [ArduinoLog](https://github.com/thijse/Arduino-Log) ```mermaid graph TD JsonUtils --> ArduinoJson JsonUtils --> ArduinoLog ``` ## BEHAVIOUR ```mermaid graph TD Start([Parse JSON Field]) --> CheckField{Field exists?} CheckField -- Yes --> CheckType{Correct type?} CheckField -- No --> UseDefault[Use default value] CheckType -- Yes --> AssignValue[Assign parsed value] CheckType -- No --> LogWarning[Log warning] --> UseDefault AssignValue --> End([End]) UseDefault --> End ``` ## TODOS ### PERFORMANCE - Consider providing batch parsing functions to reduce parsing overhead for multiple fields - Evaluate memory usage when parsing large JSON objects ### SECURITY - Currently no validation for value ranges; consider adding range validation options - Implement protection against malformed JSON that could lead to buffer overflows ### COMPLIANCE - Ensure all error messages follow consistent formatting standards - Consider adding more documentation for compliance with project coding standards ### RECOMMENDATIONS - Add support for additional data types (e.g., float, string) - Consider a more structured approach to error handling (e.g., error codes or exceptions) - Add functions for array parsing and nested object traversal - Provide examples of common JSON parsing scenarios