Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
JsonService.cpp File Reference

Implementation of JsonService for loading, saving, and manipulating persistent JSON data. More...

#include "framework_config.h"
#include "DebugTrace.h"
#include "storage/JsonService.h"
#include <cstdio>
#include <cstdint>
#include <vector>
+ Include dependency graph for JsonService.cpp:

Go to the source code of this file.

Functions

nlohmann::json mergeDefaults (const nlohmann::json &target, const nlohmann::json &defaults)
 

Detailed Description

Author
Ian Archbell

Part of the PicoFramework application framework. Uses a StorageManager to load and store JSON documents on persistent storage. Supports fallback merge with default data and aliases for ease of use.

Version
0.1
Date
2025-03-31
License:\n MIT License

Definition in file JsonService.cpp.

Function Documentation

◆ mergeDefaults()

nlohmann::json mergeDefaults ( const nlohmann::json target,
const nlohmann::json defaults 
)

Merge a default JSON structure into a target, preserving existing keys.

Merge a default JSON structure into a target, preserving existing keys.

Definition at line 26 of file JsonService.cpp.

27{
28 nlohmann::json result = target;
29
30 for (auto it = defaults.begin(); it != defaults.end(); ++it)
31 {
32 const std::string &key = it.key();
33
34 if (!result.contains(key))
35 {
36 result[key] = it.value();
37 }
38 else if (result[key].is_object() && it.value().is_object())
39 {
40 result[key] = mergeDefaults(result[key], it.value());
41 }
42 }
43
44 return result;
45}
nlohmann::json mergeDefaults(const nlohmann::json &target, const nlohmann::json &defaults)

References mergeDefaults().

Referenced by mergeDefaults().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: