JSON string in for loop

How can i form JSON string of the data which is comming from a for loop

Have you tried searching the forum and the reference docs?

1 Like

Yeah i, searched in your forum :

and also in docs the data which is not inside the loop is made of JSON data type.

Maybe a more general search term would be better


After all, it doesn’t matter whether that’s done from a loop or anywhere else.
It’s also superfluous to specify data as that’s very obvious - what else would you want to wrap into a JSON string?

And for the Particle Reference Docs


Once you got the basics on how to build a JSON string (or object) you should also be able to extrapolate from there to tailor it for your needs (which you haven’t made very clear either).


So basicly i am getting my data for scanned BLE devices inside a loop which runs until Value of I reaches to count, and count is the number of beacon devices , so now I want to print all the data of these beacon devices I found in JSON format.
I have written some code for JSON string but it stores only for the last device which is found , so now in a single JSON string I want to make objects for each beacon device and then in each object all the data of that beacon found.
This is the output Of JSON I am currently getting :grinning:

Also another thing, my argon gets disconnected from cloud, again and again, Status LED also changes corresponding to reconnecting to the cloud and connected to the cloud.
I read on docs that issue is because if I am publishing data on console too fast, I have taken care of that thing also by giving delay of 1 sec but still it happens . So I want to know what all reasons can be their for reconnecting to cloud

As for building JSON goes, what you need is an array of JSON objects where you store the information of each sensor, similar to the JSON that you have right now. After that, you add this array of JSON objects to another JSON object that will be your root/base JSON.

So basically, you have to build all the information from the innermost to outermost. I’m not familiar with JSONWriter, but I guess that you can find specifics in the documentation.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.