Parsing with the Arduino_JSON.h library

I'm able to print parsed values to Serial using this example. The relevant section of the code is at the bottom of the post. Are there ways to store the data as other types of variables so I can do other things like post to ThingSpeak? I was able to store the data in a form that would post to ThingSpeak by adding these long variables. This cuts everything off after the decimal, though, and I'd like to avoid that. Are there solutions while still keeping this library? I see a lot of examples using ArduinoJson.h instead. Do I need to learn how to use that one to do what I want?

  long outsideTemp = myObject[String("main")][String("temp")];
  long outsideHumidity = myObject[String("main")][String("humidity")];
String serverPath = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + state + "," + countryCode + "&units=imperial" + "&APPID=" + ApiKey;
  Serial.println(serverPath);
  jsonBuffer = httpGETRequest(serverPath.c_str());
  Serial.println(jsonBuffer);
  JSONVar myObject = JSON.parse(jsonBuffer);
  if (JSON.typeof(myObject) == "undefined") {
    Serial.println("Parsing input failed!");
    return;
  }
  Serial.print("JSON object = ");
  Serial.println(myObject);
  Serial.print("Temperature: ");
  Serial.println(myObject["main"]["temp"]);
  Serial.print("Pressure: ");
  Serial.println(myObject["main"]["pressure"]);
  Serial.print("Humidity: ");
  Serial.println(myObject["main"]["humidity"]);
  Serial.print("Wind Speed: ");
  Serial.println(myObject["wind"]["speed"]);

I'm able to use double which will work for my purposes here. Not sure if I'll run into a future situation where I'll want to use String or one of the other types that don't seem to work.

You can give String() function a decimal, when Numbers also has that: So String(value,5) will also give you 5 decimal places. Maybe try that Out.

https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/

You mind showing us your json?

I am able to use the string function, but I have to create a double variable first and convert that.

The attached code pulls outside weather data from openweathermap.org and collects temp and humidity from 6 ESP8266 ESP-01’s scattered around my place. This data is then posted to ThingSpeak every 15 seconds. The json section is at the top of the sendInfo() function.

forum_example_2.ino (10.9 KB)