javascript - Create a JSON object dynamically Angular -


i have json object of below format. currently, hard coded. however, dynamically create json.

i have object need loop through , form json object

[ {                               name: "test1",                               enable: true,                               unit: 24350,                               unit_price: 1.0368,                               composition: [                                 {                                     asset: "asset1",                                      percentage: 15                                 },                                 {                                     asset: "asset2",                                      percentage: 10                                 },                                 {                                     asset: "asset3",                                      percentage: 5                                 },                                 {                                     asset: "asset4",                                      percentage: 35                                 },                                 {                                     asset: "asset5",                                      percentage: 20                                 },                                 {                                     asset: "asset6",                                      percentage: 15                                 }                               ]                           }, {                               name: "test2",                               enable: true,                               unit: 24350,                               unit_price: 1.0368,                               composition: [                                 {                                     asset: "asset1",                                      percentage: 15                                 },                                 {                                     asset: "asset2",                                      percentage: 10                                 },                                 {                                     asset: "asset3",                                      percentage: 5                                 },                                 {                                     asset: "asset4",                                      percentage: 35                                 },                                 {                                     asset: "asset5",                                      percentage: 20                                 },                                 {                                     asset: "asset6",                                      percentage: 15                                 }                               ]                           }] 

thanks in advance.

just use native javascript json.parse

var data = [     {       name: "test1",       enable: true,       unit: 24350,       unit_price: 1.0368,       composition: [         {             asset: "asset1",              percentage: 15         },         {             asset: "asset2",              percentage: 10         },         {             asset: "asset3",              percentage: 5         },         {             asset: "asset4",              percentage: 35         },         {             asset: "asset5",              percentage: 20         },         {             asset: "asset6",              percentage: 15         }       ]     },     {       name: "test2",       enable: true,       unit: 24350,       unit_price: 1.0368,       composition: [         {             asset: "asset1",              percentage: 15         },         {             asset: "asset2",              percentage: 10         },         {             asset: "asset3",              percentage: 5         },         {             asset: "asset4",              percentage: 35         },         {             asset: "asset5",              percentage: 20         },         {             asset: "asset6",              percentage: 15         }       ]     }]  var json = json.parse(data); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -