{dataOrList=[{subFlowParam={name=postPrivate_On_Input_OR}, type=SUB_FLOW, tReferenceName=Data_42767_OR_43873}, {subFlowParam={name=postPrivate_On_Input_OR}, type=SUB_FLOW, tReferenceName=Data_42767_OR_43870}], dataOrListInput={Data_42767_OR_43873={DatalRouteId=43873, PrivatePayLoad={name=UpdateLink, payload={"ReadingType": "PRIVATEXplorer;OperationType=Private","TestMeta": {"CustomFields": [{"Name": "LineID","Value": "Line1"},{"Name": "PhaseID","Value": "Phase1"}]}}}}, Data_42767_OR_43870={DatalRouteId=43870, PrivatePayLoad={name=UpdateLink, payload={"ReadingType": "PRIVATEXplorer;OperationType=Private","TestMeta": {"CustomFields": [{"Name": "LineID","Value": "Line1"},{"Name": "PhaseID","Value": "Phase1"}]}}}}}}
I want to convert this string object into JSON for development purpose this response comes from server (device data). I tried JSON.parse(); but not works. also tried with Javascript Convert string in a different format to Json this also for some data it works and for some not works.
2
Answers
The snippet you posted is improperly formatted. I cleaned up the first string and can use
JSON.parse
on it like this:JSON.parse will try to create an object from a JSON string. But your string is not in the JSON format. I think you need to convert this string to JSON first using JSON.stringify(mystring). Assuming this produces the JSON string correctly, you can then use JSON.parse with the output from stringify to create a javascript object. The javascript object will be easier to work with than the JSON string itself.
e.g.