{"action":"created","issue":{"url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/697","repository_url":"https://api.github.com/repos/bblanchon/ArduinoJson","labels_url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/697/labels{/name}","comments_url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/697/comments","events_url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/697/events","html_url":"https://github.com/bblanchon/ArduinoJson/issues/697","id":303970114,"number":697,"title":"JsonBuffer persistance: adding to JSON object in intervals","user":{"login":"Armannas","id":6339503,"avatar_url":"https://avatars2.githubusercontent.com/u/6339503?v=4","gravatar_id":"","url":"https://api.github.com/users/Armannas","html_url":"https://github.com/Armannas","followers_url":"https://api.github.com/users/Armannas/followers","following_url":"https://api.github.com/users/Armannas/following{/other_user}","gists_url":"https://api.github.com/users/Armannas/gists{/gist_id}","starred_url":"https://api.github.com/users/Armannas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Armannas/subscriptions","organizations_url":"https://api.github.com/users/Armannas/orgs","repos_url":"https://api.github.com/users/Armannas/repos","events_url":"https://api.github.com/users/Armannas/events{/privacy}","received_events_url":"https://api.github.com/users/Armannas/received_events","type":"User","site_admin":false},"labels":[{"id":74339347,"url":"https://api.github.com/repos/bblanchon/ArduinoJson/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-09T20:27:53Z","updated_at":"2018-03-15T08:30:36Z","closed_at":"2018-03-14T12:20:30Z","author_association":"NONE","body":"Arduino IDE: 1.8.6\r\nDevice: ESP8266\r\n\r\nHi there,\r\n\r\nI am doing ADC measurements in batches/intervals and would like to send stuff over MQTT only after n batches. In the naive case I would build a huge array(adding all measurements of all intervals to it) before adding all values to an ArduinoJSON object. To make it more memory efficient, I would like to use a buffer array that is just big enough for one interval and then intermittently add to the JSON object. In the next iteration, I would then overwrite the buffer and repeat for a few intervals. \r\n\r\nIf I understand correctly, the JsonBuffer is not persisent over function calls, so I need to do everything I want in the function where I construct the JsonBuffer. Would the best way to do this, to create a dummy function where my buffer (and some code) lives for the given amount of intervals like the code below? Or can I just create the jsonbuffer in the loop(), such that the jsonbuffer is destructed and constructed after exiting and re-entering the loop(), respectively?\r\n\r\n```c\r\nvoid loop () {\r\n    main()\r\n   }\r\n    // JsonBuffer lives in main(). Destructed after 4 batches.\r\n    void main(void) {\r\n        StaticJsonBuffer<SOME_BUFFER_SIZE> jsonBuffer; \r\n       JsonObject& root = jsonBuffer.createObject();\r\n       JsonArray& jsonVoltage = root.createNestedArray(\"v\"); // v = voltage measurements\r\n        \r\n\r\n        // Repeat for 4 batches/intervals\r\n        while( j < 4) {\r\n            // Other things my program might want to do here\r\n\r\n            for(int i =0; i<100; i++) {\r\n                // ADC measurements here\r\n                measurement[i] = . . .\r\n            }\r\n            // JSON array population for this interval\r\n            for(int i = 0;i<100;i++) {\r\n                jsonVoltage.add(measurement[i]);\r\n            }\r\n        j++\r\n       }\r\n      \r\n       // Reset batch measurement counter\r\n       j = 0\r\n\r\n       char buff[SOME_BUFFER_SIZE];\r\n       root.printTo(buff,sizeof(buff)); \r\n   \r\n       // Send through MQTT and do other stuff the program might want to do\r\n    }\r\n    // Exited main function. JsonBuffer is destructed and a new one is created \r\n    // when re-entering the loop\r\n}\r\n\r\n```\r\n\r\nIt might be a trivial question, but I would just like to know what the cleanest option would be.\r\n\r\nThanks.\r\n\r\nPS:\r\nAlso thanks for the nice library, very motivational to dive into C++ more.\r\n"},"comment":{"url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/comments/373298491","html_url":"https://github.com/bblanchon/ArduinoJson/issues/697#issuecomment-373298491","issue_url":"https://api.github.com/repos/bblanchon/ArduinoJson/issues/697","id":373298491,"user":{"login":"bblanchon","id":5462433,"avatar_url":"https://avatars1.githubusercontent.com/u/5462433?v=4","gravatar_id":"","url":"https://api.github.com/users/bblanchon","html_url":"https://github.com/bblanchon","followers_url":"https://api.github.com/users/bblanchon/followers","following_url":"https://api.github.com/users/bblanchon/following{/other_user}","gists_url":"https://api.github.com/users/bblanchon/gists{/gist_id}","starred_url":"https://api.github.com/users/bblanchon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bblanchon/subscriptions","organizations_url":"https://api.github.com/users/bblanchon/orgs","repos_url":"https://api.github.com/users/bblanchon/repos","events_url":"https://api.github.com/users/bblanchon/events{/privacy}","received_events_url":"https://api.github.com/users/bblanchon/received_events","type":"User","site_admin":false},"created_at":"2018-03-15T08:30:36Z","updated_at":"2018-03-15T08:30:36Z","author_association":"OWNER","body":"You're welcome @Armannas. \r\nThank you for using ArduinoJson.\r\n\r\nIf you like this project [please add a ⭐️ ](https://github.com/bblanchon/ArduinoJson/stargazers)"}}
{"actor":{"display_login":"bblanchon"}}