I have a json output but unfortunalty, I cannot parse it with any json library as the devices I am running my script on cannot be update.
Depending on the device model I am getting slightly different outputs(note the space before the colon):
json_output1='{ "var1" : "result1", "var2" : "result2", "var3" : "result3", "var4" : "10" }'
or
json_output2='{ "var1": "result1", "var2": "result2", "var3": "result3", "var4": "10" }'
I found a way to parse this as a string with string:match() and regex like so
var1, var2, var3, var4 = json_ouptut1:match('.+"var1" : "([^"]+)"'
.. '.+"var2" : "([^"]+)"'
.. '.+"var3" : "([^"]+)"'
.. '.+"var4" : "([^"]+)"')
print(var2)
--[[ OUTOUT
$lua main.lua
result2
--]]
This work and I am happy with it but it only work for one or the other output because of the space before the colon.
Any idea how I could have this working for either string ?
thanks