JSON is a data format. One of the things it is used for is communication between the client and the server web.
Each side doesn’t need to know the technology that’s on the other side, so there are patterns regulating communication. In fact the server does not need to know if it is serving a web browser, a mobile application, a desktop software or even another server. Much less need to know what technology is making the request, as long as it follows the established standards.
The same goes the other way. Essentially any programming language can be used to provide results for requesters as long as they follow these standards. And much of the standard can be met through a web server like Apache or IIS, so your C application just needs to know how to deliver the result to this server.
The data requested by Javascript in a browser or may not be delivered within any format, provided that the script requisite knows what to do with it. Of course it is not common and it is not usually worth creating own formats.
Initially the proposed format to use for asynchronous requests was XML. Hence the X of the name AJAX. But the format was considered heavy and complicated and was almost universally replaced by JSON, lighter and simpler.
Unless you have a good reason to choose another format or other form of communication, it is best to follow this same consecrated.
So if your C application that will meet the requests received by the HTTP server is able to format the data in JSON, do this and it will be well served. If she is not able and cannot solve this, she will have to choose a format and adapt JS to understand this format.
If you are doing something that will be consumed by third parties it is best to use something very standard, even if you have an extra difficulty, or even an extra layer.
Some may find that a binary format can move less data. This may be true in some situations. But it is possible to compress text data and reduce traffic. Depending on the amount of data it may not compensate. Adopt a binary format has complicated and although feasible, it is not common to be adopted.
Don’t do something different in C than you would do in other language unless you have some requirement that requires a change.
+1 For AP reference, formats used for this purpose are commonly called data exchange format (data exchange format), or sometimes exchange format / Interchange (but not to be confused with the format
.dif
).– mgibsonbr
I agree with this but despite the commonly accepted definition (on the official page and Wikipedia for example) still being the data exchange format, today it is used for more than this.
– Maniero
sorry for the delay to comment, I did not understand exactly if it is possible to use JSON to recover C results. What is the best way to be done? Because I was told that several large web systems use C++ as the lowest layer, but I didn’t see anything on the internet talking about it.
– Asura Khan
Yes, it is. The best way is somewhat vague, it is not possible to answer this. It is rare that C or even C++ is used for this. Their goal is to serve another type of application. Doing it in C is essentially the same as doing it in any language, only you’ll have to manage the memory, you’ll have to create a lot of your own to better handle it, you’ll probably have to choose a proper library for what you need since there’s nothing standardized.
– Maniero
Maybe this blibioteca will help a little.: https://github.com/Microsoft/cpprestsdk
– Tobias Mesquita