I’m interested in a valid JSON output from API, using Blynk local server.
This is what I’ve found by using Blynk LIbrary:
blynk-library/linux/main.cpp on Raspberry
…
char *buffer = "{\"load\": 0}, {\"temp\": 48}, {\"power\": 241}";
Blynk.virtualWriteBinary(V44, buffer, strlen(buffer));
Data internally sent is:
{“load”: 0}, {“temp”: 48}, {“power”: 241}
this can be easily seen:
- via fprintf in virtualWriteBinary() in src/Blynk/BlynkApi.h (Blynk Library)
or - ngrep -x -q -d lo ‘’ ‘port 8442’
but the data seen from Blynk Server API is:
massi# curl http://192.168.1.121:8080/TOKEN/get/V44
["{“load”: 0}, {“temp”: 48}, {“power”: 241}"]
You can see the leading [" and trailing "]
The output data, assuming I’d like to have JSON, is not valid: the [" and "] should be removed, at least the trailing and leading ".
Example with jq
-
JSON error
massi# echo ‘["{“load”: 0}, {“temp”: 48}, {“power”: 241}"]’ | jq
parse error: Invalid numeric literal at line 1, column 9 -
" removed, it works
echo ‘[{“load”: 0}, {“temp”: 48}, {“power”: 241}]’ | jq
massi# echo ‘[{“load”: 0}, {“temp”: 48}, {“power”: 241}]’ | jq
[
{
“load”: 0
},
{
“temp”: 48
},
{
“power”: 241
}
]
Would it be possible to add an option for that or a new API call?
Something like:
GET /TOKEN/get/V44?json
GET /TOKEN/jsonget/V44
which can remove both [", "] or at least the " in the API output
My Blink Server version is: 0.28.9
Thanks.