Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting C variables into JSON Format

Tags:

json

c

I need a C program where my C string variables need to be converted into JSON string variables. The string variables I have in my C program are: char mcode[20]="123456"

billno[20]="0057",customerId[10]="8989898",name[20]="abc",details[20]={"FMCG","90000"};
float total=135000;

And I want the above values to be converted into JSON code as shown in below format:

{ 
  "mcode":"123456" ,
    "bill": {
        "no": "0057",
        "customerId": "8989898",
        "name":"abc", 
        "details": [{"category":"FMCG","amount":90000},   {"category":"Electronics","amount":45000}]
    },
    "total":135000 
}

Help me in finding the code in C.

like image 876
Nikhil Avatar asked Jan 18 '26 09:01

Nikhil


1 Answers

You haven't put up any code to show how you are trying (and failing) to JSON encode those variables.

All I can suggest is a C library such as http://www.digip.org/jansson/ to handle that side of it.

like image 185
benosteen Avatar answered Jan 19 '26 23:01

benosteen