Skip to main content
Added an explanation of why I want to do what I asked
Source Link

I am using ArduinoJson and ESP8266HTTPClient.

Say I have a DynamicJsonDocument that has an unknown number of entries with information on different persons:

[
    {
        "ID": "12345", 
        "name": "John Smith", 
        "Address": "Street 1"
    }, 

    .
    .
    .

    {
        "ID": "00345", 
        "name": "Paul Anderson", 
        "Address": "Street 2"
    }
]

I would like to somehow store the values associated with the key "name" for all the different persons. For example, have something like:

String name1 = "";
...
String nameN = "";

.
.
.

Serial.println(name1);
...
Serial.println(nameN);

To print a list of all the names:

John Smith
Paul Anderson

The only information of the JSON I have beforehand is the keys each entry will have. I do not know how many entries there will be.

How can I go about this?

EDIT: Why I want to do this:

I am using the ESP as a client to get information from a server in the form of a JSON similar to what I wrote above. At the same time, I am serving a simple HTML website by doing server.send(200, "text/html", HTML_code); using the ESP as an AP. I was able to just cram the whole JSON into the HTML as text, but I would like to just have specific information from the JSON, as explained above.

I am aware what I am doing is far from elegant or the "correct way to do it", but I am learning all of this, so any criticism and help is more than welcome :)

I am using ArduinoJson and ESP8266HTTPClient.

Say I have a DynamicJsonDocument that has an unknown number of entries with information on different persons:

[
    {
        "ID": "12345", 
        "name": "John Smith", 
        "Address": "Street 1"
    }, 

    .
    .
    .

    {
        "ID": "00345", 
        "name": "Paul Anderson", 
        "Address": "Street 2"
    }
]

I would like to somehow store the values associated with the key "name" for all the different persons. For example, have something like:

String name1 = "";
...
String nameN = "";

.
.
.

Serial.println(name1);
...
Serial.println(nameN);

To print a list of all the names:

John Smith
Paul Anderson

The only information of the JSON I have beforehand is the keys each entry will have. I do not know how many entries there will be.

How can I go about this?

I am using ArduinoJson and ESP8266HTTPClient.

Say I have a DynamicJsonDocument that has an unknown number of entries with information on different persons:

[
    {
        "ID": "12345", 
        "name": "John Smith", 
        "Address": "Street 1"
    }, 

    .
    .
    .

    {
        "ID": "00345", 
        "name": "Paul Anderson", 
        "Address": "Street 2"
    }
]

I would like to somehow store the values associated with the key "name" for all the different persons. For example, have something like:

String name1 = "";
...
String nameN = "";

.
.
.

Serial.println(name1);
...
Serial.println(nameN);

To print a list of all the names:

John Smith
Paul Anderson

The only information of the JSON I have beforehand is the keys each entry will have. I do not know how many entries there will be.

How can I go about this?

EDIT: Why I want to do this:

I am using the ESP as a client to get information from a server in the form of a JSON similar to what I wrote above. At the same time, I am serving a simple HTML website by doing server.send(200, "text/html", HTML_code); using the ESP as an AP. I was able to just cram the whole JSON into the HTML as text, but I would like to just have specific information from the JSON, as explained above.

I am aware what I am doing is far from elegant or the "correct way to do it", but I am learning all of this, so any criticism and help is more than welcome :)

Source Link

How to get a specific value from an unknown number of JSON representations?

I am using ArduinoJson and ESP8266HTTPClient.

Say I have a DynamicJsonDocument that has an unknown number of entries with information on different persons:

[
    {
        "ID": "12345", 
        "name": "John Smith", 
        "Address": "Street 1"
    }, 

    .
    .
    .

    {
        "ID": "00345", 
        "name": "Paul Anderson", 
        "Address": "Street 2"
    }
]

I would like to somehow store the values associated with the key "name" for all the different persons. For example, have something like:

String name1 = "";
...
String nameN = "";

.
.
.

Serial.println(name1);
...
Serial.println(nameN);

To print a list of all the names:

John Smith
Paul Anderson

The only information of the JSON I have beforehand is the keys each entry will have. I do not know how many entries there will be.

How can I go about this?