Nikhil
Nikhil

Reputation: 33

Converting C variables into JSON Format

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.

Upvotes: 3

Views: 788

Answers (2)

Paulo Aquino
Paulo Aquino

Reputation: 902

There is a list of useful resources at the bottom of the JSON format home page.

Upvotes: 1

benosteen
benosteen

Reputation: 1366

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.

Upvotes: 3

Related Questions