File indexing completed on 2024-04-28 05:49:27

0001 /*
0002     SPDX-FileCopyrightText: 2019 Mark Nauwelaerts <mark.nauwelaerts@gmail.com>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QJsonObject>
0010 
0011 namespace json
0012 {
0013 // local helper;
0014 // recursively merge top json top onto bottom json
0015 QJsonObject merge(const QJsonObject &bottom, const QJsonObject &top)
0016 {
0017     QJsonObject result;
0018     for (auto item = top.begin(); item != top.end(); item++) {
0019         const auto &key = item.key();
0020         if (item.value().isObject()) {
0021             result.insert(key, merge(bottom.value(key).toObject(), item.value().toObject()));
0022         } else {
0023             result.insert(key, item.value());
0024         }
0025     }
0026     // parts only in bottom
0027     for (auto item = bottom.begin(); item != bottom.end(); item++) {
0028         if (!result.contains(item.key())) {
0029             result.insert(item.key(), item.value());
0030         }
0031     }
0032     return result;
0033 }
0034 
0035 }