I have a device which is sending data as JSON object as below, Would anyone help to convert that data into key/value pair by using Javascript as I am not very good in JS.
Below is the packet I am recieving.
2022-10-16 07:41:20,348 { "IsForward": false, "Name": "IgnitionOn", "Fields": [ { "Type": "signedint", "Name": "Latitude", "Value": "5460000" }, { "Type": "signedint", "Name": "Longitude", "Value": "10860000" }, { "Name": "Speed", "Value": "0" }, { "Name": "Heading", "Value": "361" }, { "Name": "EventTime", "Value": "1665906013" }, { "Name": "GpsFixAge", "Value": "1023" }, { "Name": "IsIgnitionOn", "Value": "true" }, { "Name": "Odometer", "Value": "0" }, { "Name": "CellStatus", "Value": "ServerConnected" }, { "Name": "CellRoamingList", "Value": "White" }, { "Name": "CellRssi", "Value": "10" } ], "SIN": 254, "MIN": 4 }
CodePudding user response:
you need to use JSON.parse()
for example JSON.parse(packet)
CodePudding user response:
JSON.parse(json) is used to convert JSON to Javascript objects/arrays and JSON.stringify(objects) can convert normal JS objects/arrays to JSON...