parse serial data into json library

Hi, I'm struggling with a problem. I use an esp8266 to recieve weather information from an api, this data is send over serial to my arduino. The data gets to the arduino, but I can't parse it in to the json library. Can someone help me out? thanks in advance!

my code:

#include <ArduinoJson.h>
StaticJsonBuffer<1600> jsonBuffer;

void setup() {
  Serial.begin(115200);

}

void loop() {
  if (Serial.available()>0)
    {
       String s = Serial.readStringUntil("#");   // Until CR (Carriage Return)
       s.replace("#", "");
       Serial.println(s);

        JsonObject& root = jsonBuffer.parseObject(s);
      
        // Test if parsing succeeds.
        if (!root.success()) {
          Serial.println("parseObject() failed");
          return;
        } else {
          Serial.println("done");
        }
             
        const char* naam = root["location"]["name"];
        
        Serial.println(naam);
        Serial.println("done");
    }

}

The arduino recieves this data over the serial monitor:

{"location":{"name":"Paris","region":"Ile-de-France","country":"France","lat":48.87,"lon":2.33,"tz_id":"Europe/Paris","localtime_epoch":1535570599,"localtime":"2018-08-29 21:23"},"current":{"last_updated_epoch":1535569210,"last_updated":"2018-08-29 21:00","temp_c":17.0,"temp_f":62.6,"is_day":0,"condition":{"text":"Partly cloudy","icon":"//cdn.apixu.com/weather/64x64/night/116.png","code":1003},"wind_mph":8.1,"wind_kph":13.0,"wind_degree":310,"wind_dir":"NW","pressure_mb":1019.0,"pressure_in":30.6,"precip_mm":0.0,"precip_in":0.0,"humidity":63,"cloud":75,"feelslike_c":17.0,"feelslike_f":62.6,"vis_km":10.0,"vis_miles":6.0}}

but I can't parse it in to the json library.

Why can't you?

StaticJsonBuffer<1600> jsonBuffer;

Are you REALLY expecting 1600 bytes of data? That's 80% of the Arduino's SRAM.4

Why isn't the ESP parsing the data, and just giving you what you want?

Hi, that's the problem. It's looks all fine, but I dont now why it doen't works. I recieve 619 characters, I'm parsing a string so there has to be some extra space to copy the buffer, thats what i've readed.

but I dont now why it doen't works.

You have not defined what the program actually does, or how that differs from what you want, so it is pointless to talk about the program working/not working.

well I think I dont get it but ok, the setup is an esp8266 that has a serial communication with an arduino uno R3. the esp8266 gets the data from an api, the returned data is the data from my first post. The data is sended over serial communication to the arduino Uno, this data has to be parsed in my json library. so I can take the variables and display them to an lcd display from ardafruit. When I tried to parse this string I get a parse error. I searched an tried for hours but I don't see my fault. thats what I'm asking

code from the esp:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
 
const char* ssid = "********";
const char* password = "*********";
 
void setup () {
 
  Serial.begin(115200);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
 
    delay(1000);
    Serial.print("Connecting..");
 
  }
 
}
 
void loop() {
 
  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
 
    HTTPClient http;  //Declare an object of class HTTPClient
 
    http.begin("http://api.apixu.com/v1/current.json?key=****************&q=Paris");  //Specify request destination
    int httpCode = http.GET();                                                                  //Send the request
 
    if (httpCode > 0) { //Check the returning code
 
      String payload = http.getString();   //Get the request response payload
      Serial.println(payload);                     //Print the response payload
 
    }
 
    http.end();   //Close connection
 
  }
 
  delay(5000);    //Send a request every 30 seconds
 
}

The ESP has WAY more memory than the Arduino. Why isn't it doing the json parsing?

You have a String object that wraps 612 characters. That leaves you less than 1400 bytes of SRAM in which you try to create a StaticJsonBuffer of 1600 bytes PLUS all the memory required to parse the JSON string.

Can you really stuff 10 pounds of sand in a 5 pound bag?

yess you're right, I'm going to try to do it with the esp. Thanks for the help!

sebastiaan_maes:
Hi, that's the problem. It's looks all fine, but I dont now why it doen't works. I recieve 619 characters, I'm parsing a string so there has to be some extra space to copy the buffer, thats what i've readed.

In a string a space is still considered 1 char. So depending on what method you are using to establish the length, it is probably including those spaces in the count.