I am developing a Web Page which receives below data over socket:
{
"version": 1,
"timestamp": "1990-01-01T02:10:45.265Z",
"points": {
"motor_voltage": {
"present_value": 0
},
"motor_current": {
"present_value": 0
},
"speed_rpm": {
"present_value": 0
},
"running_hours": {
"present_value": 1
},
"drive_temperature": {
"present_value": 0
},
"analog_input_2": {
"present_value": 0
},
"status_word": {
"present_value": "600hex"
},
"digital_input": {
"present_value": 64
},
"digital_output": {
"present_value": 0
}
}
"booldigital_output": {
"present_value": 0
}
}
I have tried a log how use JavaScript to parse this string and extract like below
motor_voltage: { present_value: 0 }
And all others – like we get each key value present_values in an array? If I call JSON.parse method – it throws an error that object is not in JSON format.
How can I extract the data from above string as per the values required?