Opening API url in C++ (json or XML)

There is API data on a website offered in JSON and XML. In Python, I can call the data by using a url importer and a json converter rather simply.
1
2
3
4
5
6
7
   import urllib.request
   import json

    def main():
        response=urllib.request.urlopen("url_here").read()
        json_obj=str(response, 'utf-8')
        data=json.loads(json_obj)

Then, I could loop "data" like a list to access the API data. How could I do this in C++? So far, I've seen "file" (not URL) examples suggesting I need secondary software. Is there not a simpler way to do this on my IDE? To A) import a url and B) access the data? And should I use Json or XML when importing API data from a url in regards to C++? I found it easier with Python to use json but I'm suspecting in C++, XML might be better.

Do you need to do this in C++? libcurl (an HTTP client implementation) is not exactly a beginner-friendly library. Have you considered simply calling into C++ from Python using a foreign function call and then processing the data in C++?

https://docs.python.org/2/extending/extending.html
https://docs.python.org/3/extending/index.html
The C++ std library does not provide networking support. There is a draft technical paper discussing a possible future networking library in the std library, but that's as far as it goes.

You're going to have to use a 3rd party library.

CURL is very popular and widespread, with lots of examples available.

I don't have to use C++ but I would really like too. My goal was to make this in both Python and C++, however I'm up for calling the data from Python if need be. I'll look into this foreign function call.
I'm seeing a lot of examples in C, but is there an example of calling a python function from a .py file in C++?
Are you looking at extending Python or embedding Python? Extending Python means to call functions in a different language from Python, while embedding Python means to call the Python interpreter as a library, from a different language.
What I'm suggesting is to use Python to download the content and then call into C++ (extending) to process it.
The examples in the Python documentation for extending will probably use C, but you can use C++, too. You just have to export the function you want to expose to Python as C functions.

1
2
3
4
extern "C" void this_is_a_function_callable_from_c(const char *string){
    std::string s = string;
    std::cout << s << std::endl;
}
Extending it. I understand the concept pf calling the Python function from C++, just looking for C++ examples.
Seems confusing because there's numerous examples using 3rd party libraries (most notably boost). Is that required to simply extend a python function into C++?
No, you only need a C++ compiler and Python, IIRC.
Registered users can post here. Sign in or register to post.