Answer the question
In order to leave comments, you need to log in
Match two Json?
Good afternoon guys, maybe someone has already done something similar.
Let's say there is a main json file with some data, and the second one is the same, but with slightly different information.
We do not know how many lines it will contain, and what nestings will be, is it possible to create a function that will compare these two files, and if they differ in the second file, will they overwrite the information from the first file?
I'm wondering how this can be implemented, and whether it is possible.
Answer the question
In order to leave comments, you need to log in
It is possible, but in any case, the function must understand what to compare with, i.e. the data structure must be defined.
Those. if in one array there is an object that contains properties, then in another object there must be properties that have the same key, or it is necessary to write in the conditions that "the name of such an object key from json2 is read as ..."
If at least part of json 'and you can look, then you can say something concrete.
Object.keys(obj)
you receive keys, then you check the data on these keys. If a primitive data type, then overwrite the strass, if an array, then go through the values and repeat the procedure, if the object repeats the procedure. All that does not exist in the first add from the second.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question