DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Ashok Mohanakumar
Ashok Mohanakumar

Posted on

Make get request and parse JSON in C?

I'm trying to learn C and get comfortable with it. How do I make HTTP requests?
What do I do to handle JSON?

Top comments (11)

Collapse
hoelzro profile image
Rob Hoelz

Out of curiosity, what's your motivation for learning C? I think that trying something like making HTTP requests and parsing JSON is going to be very frustrating if you're just trying to learn, and depending on what you intend to use it for, may not be something you end up doing in C anyway!

Collapse
ashokcodes profile image
Ashok Mohanakumar Author

I am trying to build a service that makes post request to an API that provides IVR functionalities and handles the response and manages many things such as retries, call status, etc
Just wanted to try doing some http stuff with C

Collapse
hoelzro profile image
Rob Hoelz

Any particular reason you want to do this in C rather than a higher-level language (eg. running on an embedded device)? Or just as an exercise to learn C?

Collapse
donaldsebleung profile image
Donald Sebastian Leung

Unless you really want to understand the lowest levels of how HTTP requests work or practice your parsing skills by implementing your own JSON parser, I would recommend googling for "HTTP requests in C", "JSON parser in C" or the like - there are plenty of third-party libraries in C which do the heavy lifting for you. For example:

Collapse
ashokcodes profile image
Ashok Mohanakumar Author

Thanks a lot !!

Collapse
snhilde profile image
Hilde N

I use CURL and cJSON for these issues.

You can see some examples for GET and POST requests in this parser program. You would be interested in get_weather() (and its two parser functions) and get_portfolio_value()/parse_portfolio_json() for GET requests and parsing the jsons and get_token() as an example of a POST request.

Hilde

Collapse
apolzek profile image
VinΓ­cius Gomes

{"url":"0.0.0.0:4500/api/SensorData/Add","... \"id\": \"string\", \"humidity\": 0}":""}}

Collapse
cosminpopescu14 profile image
Cosmin Popescu

Although it is not in plain C (ANSI C) check this out

github.com/nlohmann/json

Collapse
aghost7 profile image
Jonathan Boudreau

I've never tried it, but this framework looks interesting: kore.io/

Here's an example using yajl to parse JSON:

git.kore.io/kore/file/examples/jso...

Collapse
mrajarao76 profile image
Raja Rao

{
"piGroup":" ",
"nonSerializedScanData": [],
"serializedScanData": [],
"piType": "MINI",
"isLastUser": true,
"sessionId": ""
}

Collapse
thulasiram_ponnam_8d5e32b profile image
!2C RAM @ jsonformatter.dev • Edited on

try & instantly validate and Beautify JSON using jsonformatter.dev

Find what you were looking for? Join hundreds of thousands of developers on DEV so you can:

Β 
🌚 Enable dark mode
πŸ”  Change your default font
πŸ“š Adjust your experience level to see more relevant content