Skip to content

JSON Utilities

Path: 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.

  • ArduinoJson library
  • ArduinoLog library
  • 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
  • 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

JsonUtils

ArduinoJson

ArduinoLog

Yes

No

Yes

No

Parse JSON Field

Field exists?

Correct type?

Use default value

Assign parsed value

Log warning

End

  • Consider providing batch parsing functions to reduce parsing overhead for multiple fields
  • Evaluate memory usage when parsing large JSON objects
  • Currently no validation for value ranges; consider adding range validation options
  • Implement protection against malformed JSON that could lead to buffer overflows
  • Ensure all error messages follow consistent formatting standards
  • Consider adding more documentation for compliance with project coding standards
  • 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