-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using json merge_patch on ordered non-alphanumeric datasets #1549
Comments
I am not sure whether this is possible with JSON Merge Patch (https://tools.ietf.org/html/rfc7386). With JSON Patch (https://tools.ietf.org/html/rfc6902), however, it should be possible with an |
Thanks for the reply. Yes, the merge_patch only seems to replace particular values if inside objects from the top level down because of the way that the algorithm works. I think that arrays may be treated just as a lowest level value which is just cleared and replaced with the merge data instead of leaving values that do not get changed in the new data. |
By the way: the |
I have found through testing that "update" also seems to clear anything in the highest level array and write in only the changes instead of adding them to other existing information. It appears to share the same overall design ideas of "patch" and "merge_patch". I'm sure that this is an unintended flaw since many json users do not care about the ordering of the data keys in the output. I just need to maintain that ordering for the users who look at the settings after using our software so I use arrays to ensure the order stays the same. On the other hand, I was able to manually create json_pointer lines that add new values to existing data or overwrite the previous values correctly by creating a unicode string for the locations. I would have to find the locations ahead of every merge with specific 'find' operations and somehow use the json_pointer syntax. I tried substituting a generated string into the syntax but it does not seem to work, for example:
Is there a way to use automatically generated strings in the pointer syntax for my update problem? Also, has any users had luck doing 'update' style changes to their json if they use the "fifo_map" format that you have suggested in other posts for ordered data? |
You can create a JSON Pointer from a string with this constructor: https://nlohmann.github.io/json/classnlohmann_1_1json__pointer_a7f32d7c62841f0c4a6784cf741a6e4f8.html#a7f32d7c62841f0c4a6784cf741a6e4f8 |
Ok, thanks for the link. |
@jjhand21 Do you need further assistance on this issue? |
No. I decided to use pyhocon on the data ingest in order to meet other requirements I had, and then merge in that format before handling data as a pure json type. Thanks for the suggestions though. |
I would like to use json merge patching in the following manner:
Describe what you tried.
I have tried the merge_patch method but it removes anything inside the high level organizational array of the main file and then just inserts what is in the patch. I imagine that removing the [ ] around the sets would allow this to work but I would lose the starting order of entries in my main file's input. This file will be dumped to the user to show them what settings were used during use of a software algorithm that uses the values so keeping the order the same is very helpful. I am attempting to see if "diff" will help in this situation, but if it does not I will have to find a way to have ordered data that can be patched in this manner so the user can have a complete set of ordered settings between defaults and their selected changes.
Describe which system (OS, compiler) you are using.
Redhat 7.6, GCC 4.8.5
Describe which version of the library you are using (release version, develop branch).
Release Version
The text was updated successfully, but these errors were encountered: