對象替換字符串我有3個JSON文件:與其他JSON文件
- sources.json
- destination_level1.json
- destination_level0.json(最後文件)
我想通過替換匹配的字符串「合併」所有這些文件,例如
destination_level0 - > destination_level1 - > sources
用詞語:「檢查destination_level0中的鍵例如「部件1」,去destination_level1和查找匹配的對象,並在destination_level0與對象替換部件1「也是一樣從destination_level1消息人士透露
來源可能是這樣的:。
{"john": ["A","B"],"mike": ["123","234","345"],"doe": ["abc","cde"],"ann": {"abc": ["yxc","xcv","cvb"],"bcd": ["poi","iuz","uzt"]}}
destination_level_1像這樣的:
{"Element1": ["john","ann","john","john","doe","mike"],"Element2": ["ann","mike","ann","doe","doe","doe","ann"],"Element3": ["ann","doe","ann"]}
和destination_level_0這樣的:
{"FinalA": ["Element1","Element2","Element1","Element2","Element2"],"FinalB": ["Element2","Element2","Element2","Element1"]}
最後的結果應該是這樣的:
{"FinalA": [[["A","B"],{"abc": ["yxc","xcv","cvb"],"bcd": ["poi","iuz","uzt"]},...
我已經嘗試了一些lodash &底線,但卡住了。
任何想法?
element2從哪裏來? finalB從哪裏來?關係不清楚! –
element2在destination_level0.json中手動定義。 finalB一樣。 element2應該替換爲destination_level_1中element2的對象。由於這是我們將要使用的最終「關鍵」,因此finalB不需要被替換。我希望澄清它? – Vinzent