My function receives a JSON string that may have syntax error, how can I fix the error in my function so that I can call JSON.parse()?
Question story: I want to parse the command output of sudo lshw -class network -json which is a linux command. For example, the PC has 2 NICs, so the command output has 2 JSON objects. An exmpale is as following:
{
"businfo" : "pci@0000:01:00.0",
some other keys
}
{
"businfo" : "usb@1:4",
some other keys
}
NOTE: the 2 objects has no "," seperator. So JSON.parse() will generate error.
ODD: another hyper-v vm's lshw has the same version as used above, but it can generate correct JSON with "," between 2 objects. Same command line.
IF the only problem is that there is no comma between the objects and the format of the string is the same you can do string replace for '} {' to '}, {', and then the resulting string should be parseable. Hope that would help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With