Oh actually, scrap that, it’s an enablable option: Can't compile ArduinoJson with GNU++11 · Issue #548 · bblanchon/ArduinoJson · GitHub.
[env:native]
platform = native
build_flags = -std=gnu++11 -DARDUINOJSON_ENABLE_ARDUINO_STRING=1
lib_deps =
https://github.com/FabioBatSilva/ArduinoFake/archive/refs/heads/master.zip
https://github.com/bblanchon/ArduinoJson/archive/refs/heads/6.x.zip
with
#include <stdio.h>
#include <Arduino.h>
#include <ArduinoJson.h>
int main() {
printf("Hello, world!\n");
DynamicJsonDocument doc(1024);
// You can use a String as your JSON input.
// WARNING: the string in the input will be duplicated in the JsonDocument.
String input =
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
deserializeJson(doc, input);
JsonObject obj = doc.as<JsonObject>();
long time = obj[String("time")];
printf("Time: %ld\n", time);
String sensor = obj["sensor"];
printf("Sensor: \"%s\"\n", sensor.c_str());
return 0;
}
works exactly the same.
>.pio\build\native\program.exe
Hello, world!
Time: 1351824120
Sensor: "gps"