void Value::merge(const Value &value) {
  // Merge lists
  if (isList() && value.isList()) {
    appendFrom(value);
    return;
  }

  if (!isDict() || !value.isDict())
    TYPE_ERROR("Cannot merge JSON nodes of type " << getType() << " and "
               << value.getType());

  // Merge dicts
  for (unsigned i = 0; i < value.size(); i++) {
    const string &key = value.keyAt(i);
    ValuePtr src = value.get(i);

    if (has(key)) {
      ValuePtr dst = get(key);

      if ((src->isDict() && dst->isDict()) ||
          (src->isList() && dst->isList())) {
        dst->merge(*src);
        continue;
      }
    }

    insert(key, src);
  }
}
Exemple #2
0
void Dict::insert(const string &key, const ValuePtr &value) {
  if (value->isList() || value->isDict()) simple = false;
  OrderedDict<ValuePtr>::insert(key, value);
}