Skip to content Skip to sidebar Skip to footer

How To Convert Json Array To Json Object In Javascript

I have a json array like in the below image: JSon array I want it to be onyl json object and not array. Like when I do JSON.stringify I get this: [{'total_exec_qty':'286595','total

Solution 1:

just reference the object like this:

vararray = [{"total_exec_qty":"286595","total_notional":"21820771.72","total_wt_arr_last_slp":"2.4364","total_num_ords":"1630","total_wt_ivwap_slp":"6.0969","total_wt_arr_slp":"1.7889","total_ord_qty":"576991"}];

varobject = array[0];

Alternatively you could copy the object and reassign it to the same variable like the following, note: This second method is a bit more expensive.

vardata = [{"total_exec_qty":"286595","total_notional":"21820771.72","total_wt_arr_last_slp":"2.4364","total_num_ords":"1630","total_wt_ivwap_slp":"6.0969","total_wt_arr_slp":"1.7889","total_ord_qty":"576991"}];

data = JSON.parse(JSON.stringify(data[0]));

Here is a working example.

Post a Comment for "How To Convert Json Array To Json Object In Javascript"