squix78 / json-streaming-parser

Arduino library for parsing potentially huge json streams on devices with scarce memory
MIT License
205 stars 88 forks source link

Help with Streaming Parser 2 #30

Closed 1CM69 closed 1 year ago

1CM69 commented 4 years ago

Hi mrfaptastic #dayrate

I am struggling a little in using your fork to parse a JSON file, the default example you include works perfectly but I cannot seem to implement with my own file: https://covid.ourworldindata.org/data/owid-covid-data.json

I am trying to only get info of the GBR on a specific date, see code clip below:

 if (currentKey[0] != '\0') {
    if (strcmp(currentKey, "GBR") == 0) {

      if (strcmp(currentKey, "data") == 0) {

        if (currentKey[0] != '\0') {

          if (strcmp(currentKey, "date") == 0) {

            if (strcmp(value.getString(), "2019-12-31") == 0) {
              Serial.println("We found it!");
              in_json_object_of_interest = true;
            }
          }
        }
      }
    }
    if (in_json_object_of_interest)
    {

      Serial.print(fullPath);
      Serial.print("': ");
      Serial.println(valueBuffer);
    }

 }

This is the output I get in the serial monitor:

16:13:10.062 -> [SETUP] WAIT 4...
16:13:10.576 -> [SETUP] WAIT 3...
16:13:11.062 -> [SETUP] WAIT 2...
16:13:11.561 -> [SETUP] WAIT 1...
16:13:12.071 -> Starting.........
16:13:12.071 -> Heap free:48688
16:13:12.071 -> Stack free:2144
16:13:12.208 -> Connecting.....
16:13:14.720 -> Connected, IP address: ***.***.***.***
16:13:14.720 -> Heap free:48688
16:13:14.720 -> Stack free:2080
16:13:14.720 -> SSL fingerprint set.
16:13:14.720 -> Heap free:42272
16:13:14.720 -> Stack free:2080
16:13:14.720 -> Setup JSON Streaming Parser.
16:13:14.720 -> Heap free:42272
16:13:14.720 -> Stack free:2080
16:13:14.720 -> Making HTTPS Connection.
16:13:14.720 -> Heap free:42192
16:13:14.720 -> Stack free:2080
16:13:15.576 -> [HTTP] GET... code: 200
16:13:15.576 -> Heap free:19672
16:13:15.576 -> Stack free:592
16:13:15.576 -> Got payload response of length: 18271487
16:13:15.576 -> Parsing JSON...
16:13:15.576 -> Heap free:19672
16:13:15.576 -> Stack free:592
16:13:27.231 -> 500 JSON objects parsed
16:13:38.317 -> 1000 JSON objects parsed
16:13:53.793 -> Completed Parsing.
16:13:53.793 -> Heap free:20744
16:13:53.793 -> Stack free:336
16:13:53.793 -> Done.
16:13:53.793 -> Heap free:20744
16:13:53.793 -> Stack free:336

my IP here is *** out just in case.

You can see that the connection is made but it only iterates to 1000 objects before being done, what am I missing?

Here is an excerpt from the JSON file I am trying to parse:

"GBR": {
        "continent": "Europe",
        "location": "United Kingdom",
        "population": 67886004.0,
        "population_density": 272.898,
        "median_age": 40.8,
        "aged_65_older": 18.517,
        "aged_70_older": 12.527,
        "gdp_per_capita": 39753.244,
        "extreme_poverty": 0.2,
        "cardiovasc_death_rate": 122.137,
        "diabetes_prevalence": 4.28,
        "female_smokers": 20.0,
        "male_smokers": 24.7,
        "hospital_beds_per_thousand": 2.54,
        "life_expectancy": 81.32,
        "data": [
            {
                "date": "2019-12-31",
                "total_cases": 0.0,
                "new_cases": 0.0,
                "total_deaths": 0.0,
                "new_deaths": 0.0,
                "total_cases_per_million": 0.0,
                "new_cases_per_million": 0.0,
                "total_deaths_per_million": 0.0,
                "new_deaths_per_million": 0.0
            },
            {
                "date": "2020-01-01",
                "total_cases": 0.0,
                "new_cases": 0.0,
                "total_deaths": 0.0,
                "new_deaths": 0.0,
                "total_cases_per_million": 0.0,
                "new_cases_per_million": 0.0,
                "total_deaths_per_million": 0.0,
                "new_deaths_per_million": 0.0,
                "stringency_index": 0.0
            },

Sorry about posting here but I cannot see another way to contact you.

Thanks

mrcodetastic commented 2 years ago

Apologies. I never saw this isse you raised almost a year ago. If you raised it at my fork of the library I would have seen it.