How to package 12 double variables into JSON Object (Packets)

I am developing Processing GUI for PID control.
I wish to use JSON to share data between the PC and the control board.

But i am having issue packaging the JSON object.
I need send and receive 12 variable (double).
I was able to package upto 9 doubles variables.
If i add one more (10 variables) the packet get truncated
This is the Error package:

Well packaged (maximum of 9 variables)

//This Function Send JSON Payload
typedef struct
double _1FLOWsp; //1 Flow setpoint
double _2FLOWsp; //2 Flow setpoint
double _TEMPsp; //Temperature setpoint
double _kp; //This is PID kp set by user
double _ki; //This is PID ki set by user
double _kd; //This is PID Kd set by user
double _1FLmeas; //This flow rate measured from sensor1
double _2FLmeas; //This flow rate measured from sensor2
double _TEMPmeas;
double _PWRmeas; //This is Power consumed by the system unit
double _1TANKmeas; //This is water level in the upper tank
double _2TANKmeas; //This is water level in the lower tank

void JSONpayload()
char PAYLOAD[250];


		  "{\"KP\":%.1f,"		//KP
		  "\"KI\":%.1f,"		//KI
		  "\"KD\":%.1f,"		//KD
		  "\"FSP1\":%.1f,"		//Flow rate set-point
		  "\"FSP2\":%.1f,"		//Flow rate set-point
		  "\"TPSP\":%.1f,"		//Temp set-point
		  "\"FL1\":%.1f,"		//1 Flow rate measured
		  "\"FL2\":%.1f,"		//2 FLow rate measured
		  "\"TMP\":%.1f"		//Temperature measured
		  "\"UPT\":%.1f"		//1 Tank water level
		 // "\"DWT\":%.1f"		//2 Tank water level
		 // "\"PWR\":%.1f"		//Power consumed

		 // ,data._2TANKmeas
		 // ,data._PWRmeas




How can i package 12 variables (double) into JSON.

Hi @avong, You haven’t said what control board you are using, I’m familiar with Arduino but not others. The code you posted has a sprintf so it has to be the controller code. I like sprintf and used to use it in Arduino. On one project it would not compile, and if you Google ‘arduino sprintf problem’ you’ll find lots.

You could avoid using sprintf by printing the pieces of the json packet using separate print statements. At the receiving end it will look just the same.

I am using costumed Atmega328P board, i use eclipse IDE + avr plugin.
The Processing GUI has no issue, i can read once incoming data (JSON format) from the 9 variable i could packet into JSON format.
The challenge is, i can go beyond 9 variables, when i do, i get errors (truncated packet).

I was thinking there is internal buffer declared using char* pointer which truncates my packet. but when i check i could only see extern int sprintf(char *__s, const char *__fmt, …); in stdio.h header.

Yes, alright. I started thinking ‘use 2 shorter pieces for the packet’, then thought ‘don’t bother with the packet, just print all the pieces separately and avoid sprintf completely’. There are also articles saying that using the String data type in Arduino is not very good.

I will take your first recommendation.
I ealier thought of breaking my packet into 2, but was convience to post my challenge in public, maybe someone will have experience that before.