DEV Community


Make get request and parse JSON in C?

Ashok Mohanakumar
INTP | Full Stack Dev
・1 min read

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

Discussion (11)

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!

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

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?

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:

ashokcodes profile image
Ashok Mohanakumar Author

Thanks a lot !!

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.


apolzek profile image
Vinícius Gomes

{"url":"","... \"id\": \"string\", \"humidity\": 0}":""}}

cosminpopescu14 profile image
Cosmin Popescu

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

aghost7 profile image
Jonathan Boudreau

I've never tried it, but this framework looks interesting:

Here's an example using yajl to parse JSON:

mrajarao76 profile image
Raja Rao

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

thulasiram_ponnam_8d5e32b profile image
!2C RAM @ • Edited

try & instantly validate and Beautify JSON using