You are not logged in.
Hi,
I thought I could update the JSON object with an object that only contains part of the values. Unfortunately, the child objects are overwritten with the update object child element and the existing elements are lost.
Sample:
Json to update:
d1 := DocDict('
{
"name": "Mustermann",
"address": {
"city": "Musterstadt",
"street": "Lindenallee"
}
}');
Json Update input.
d2 := DocDict('{
"surname": "Max",
"address": {
"postal_code": "12345"
}
}');
d1.Update(d2);
Output:
{
"name": "Mustermann",
"address": {
"postal_code": "12345"
},
"surname": "Max"
}
Expected:
{
"name": "Mustermann",
"address": {
"city": "Musterstadt",
"street": "Lindenallee"
"postal_code": "12345"
},
"surname": "Max"
}
I have also tried "mDefault" as Model instead of mFastFloat.
Any chance to merge the json on all levels?
Thanks,
Tobias
Offline
Hi Arnaud,
yes i want a merge.
Looking for "merge" in mormot.core.variants points me to:
/// set a value, given its path
// - path is defined as a dotted name-space, e.g. 'doc.glossary.title'
// - aCreateIfNotExisting=true will force missing nested objects creation
// - aMergeExisting=true will merge aValue object with any existing object
// - returns nil if there is no item to be set at the supplied aPath
// - returns the address of the found or created value in aValue
// - you can set e.g. aPathDelim = '/' to search e.g. for 'parent/child'
function SetValueByPath(const aPath: RawUtf8; const aValue: variant;
aCreateIfNotExisting: boolean = false; aPathDelim: AnsiChar = '.';
aMergeExisting: boolean = false): PVariant;
because of "aMergeExisting=true will merge aValue object with any existing object"
is this an option? - I tried it, but I got an exception. Also i don't realize how to "Set" the root Path.
Thank you.
Offline
Please try with
https://github.com/synopse/mORMot2/commit/5dd229b1
I have added a new Merge() method to IDocDict.
Online
Hi Arnaud,
perfect. Thank you very much.
So i was in the right direction.
Tested and verified!
Tobias
Offline