I have code that eventually collects two JSON objects, something like this.
var jsonL1 = {"holder1": {}} var jsonL2 = {"section":"0 6","date":"11/12/13"}
I would like to insert jsonL2 inside jsonL1.holder1 and merge it into a single JSON object.
Required conclusion
{ "holder1": { "section": "0 6", "date": "11/12/13" } }
How can i do this?
It is as simple as:
L1.holder1 = L2
I removed "json" from the variable names, as @patrick already said, you are not dealing with "JSON objects", but object literals.
See also: No JSON Object
You can also learn more about objects in JavaScript .
If you want the first object to refer to the second, do the following:
jsonL1.holder1 = jsonL2;
, .
, , , . , jsonL2 jsonL1.holder, .
jsonL2
jsonL1.holder
, JSON javascript:
// this is a javascript object var obj = {"section":"0 6","date":"11/12/13"}; // this is valid JSON data var jsn = '{"section":"0 6","date":"11/12/13"}';
Source: https://habr.com/ru/post/1788011/More articles:DotNetNuke Control Panel Won't Go - dotnetnukeSimulating jQuery $ .post / $. Ajax to read XML - javascriptCombine all array values - arraysПреобразование IEEE int-> float коммутирует с + и *? - floating-pointhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1788010/need-to-speed-up-c-code-involving-boost-multi-index-and-lookups-to-unorderedmultimap&usg=ALkJrhgtpl0o3oGVoeuKZAYO8iSlhx021wExtract items from a dictionary - pythonsaving values in a scheme around the world - schemeAnimated view around a circle with an arbitrary starting point - iosScheme - define a variable as the result of a function? - functionDDMS do not like ADB? - androidAll Articles