How do you convert a C struct to JSON using the JSON-C library?
-
-
Answer:
You can do it using json_pack function. Refer to https://jansson.readthedocs.org/en/2.4/apiref.html#building-values
Venkata Narasinga Rao Koppu at Quora Visit the source
Other answers
Having come across the same issue, i wrote a library that helps with this problem. https://github.com/jamie-pate/jstruct . You can annotate existing c structures, and a python script generates meta-data c headers based on the annotations. The library reads the metadata to import/export c structures to json strings and back. A python script takes care of parsing the annotated header and generating new headers and metadata initializers. The jstruct library uses https://github.com/json-c/json-c internally.I have also noticed https://github.com/marel-keytech/jsoncc but that was after writing the entire thing. (and info on that project's page is sparse)
Jamie Pate
Related Q & A:
- How do I convert a PDF file to PDF/A in Delphi?Best solution by softwarerecs.stackexchange.com
- How to Convert a C++ Structure into C# Structure?Best solution by Stack Overflow
- How do I convert a bitmap to vector?Best solution by Super User
- How can I convert a string number to a number in Perl?Best solution by Stack Overflow
- How do you convert a windows movie maker file to a regular video file?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.