N
N
Name Surname2019-09-17 14:50:09
JavaScript
Name Surname, 2019-09-17 14:50:09

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

2 answer(s)
A
Anatoly Kulikov, 2019-09-17
@anatoly_kulikov

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.

P
profesor08, 2019-09-17
@profesor08

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 question

Ask a Question

731 491 924 answers to any question