Reputation: 955
I am writing C++ using mingw-w64 g++ on windows with VS Code.
I need to be able to parse some JSON string.
mingw doesn't seem to have any built-in JSON support.
What is the way to set up JSON support in mingw-w64 on windows 10?
Upvotes: 0
Views: 585
Reputation: 955
Following Brecht's list, I tried json-parser. The following is how I made it to work. Hope this will help folks not familiar with the process
Do this from Msys terminal which came with MinGw G++, becaue it has 'make' command.
cd mycppbase
git clone https://github.com/json-parser/json-parser.git
cd json-parser
export PATH=/c/msys64/mingw64/bin:$PATH
./configure
make
three files are important
json.h
libjsonparser.a
libjsonparser.so
cd myexampledir/
g++ myjson.cpp -o myjson \
-I "/c/.../mycppbase/json-parser" \
-L "/c/.../mycppbase/json-parser" \
-l:libjsonparser.a
UPDATE: 2022/11/20
the previous example is to link a static executable.
To link dynamically, we need to rename the .so file to .dll file. (see comments below)
The following is done in gitbash terminal and worked.
mv libjsonparser.so libjsonparser.dll
cd myexampledir/
g++ myjson.cpp -o myjson \
-I "/c/.../mycppbase/json-parser" \
-L "/c/.../mycppbase/json-parser" \
-ljsonparser
Upvotes: 1
Reputation: 7287
There are quite a few libraries for handling JSON from C/C++ that you can use.
To name a few that I have been able to compile with MinGW-w64:
Description : JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects.
https://github.com/json-c/json-c
Description : Jansson is a C library for encoding, decoding and manipulating JSON data.
Description : JSON-GLib is a library providing serialization and deserialization support for the JavaScript Object Notation (JSON) format described by RFC 4627. Website URL : http://live.gnome.org/JsonGlib
Description : Very low footprint JSON parser written in portable ANSI C
https://github.com/udp/json-parser
Description : json parser for C and C++
https://github.com/sheredom/json.h
Description : jsmn (pronounced like "jasmine") is a minimalistic JSON parser in C. It can be easily integrated into the resource-limited projects or embedded systems.
Description : tiny-json is a versatile and easy to use json parser in C suitable for embedded systems. It is fast, robust and portable. It is not only a tokenizer. You can get data in string format or get the primitives values in C type variables without performance loss.
https://github.com/rafagafe/tiny-json
Description : A more user friendly layer for decoding JSON in C/C++ based on the ultra fast UltraJSON library
https://github.com/esnme/ujson4c/
Description : CAJUN is a C++ API for the JSON data interchange format with an emphasis on an intuitive, concise interface. The library provides JSON types and operations that mimic standard C++ as closely as possible in concept and design.
https://github.com/cajun-jsonapi/cajun-jsonapi
Description : JSON parser and generator for C/C++ with scanf/printf like interface. Targeting embedded systems. Website URL : https://github.com/cesanta/frozen
Description : jq is a lightweight and flexible command-line JSON processor.
https://stedolan.github.io/jq/
Description : Flexible Zero-Footprint JSON Parser in C
https://github.com/quartzjer/js0n
Description : a fast json library for C
https://github.com/rsyslog/libfastjson
Description : The libxo library allows an application to generate text, XML, JSON, and HTML output using a common set of function calls. The application decides at run time which output style should be produced.
https://github.com/Juniper/libxo
Description : Tiny JSON parser in C that uses only fixed-extent storage.
http://www.catb.org/esr/microjson/
Description : A DOM-less JSON parser that can parse a JSON object without allocating a single byte of memory
https://github.com/giacomodrago/minijson_reader
Description : A simple, little-overhead, allocation-free, and extensible C++ JSON writer, directly wrapping a std::ostream
https://github.com/giacomodrago/minijson_writer
Description : A public domain JSON parser focused on correctness, ANSI C99 compliance, full Unicode (UTF-8) support, minimal memory footprint, and a simple API. As a streaming API, arbitrary large JSON could be processed with a small amount of memory (the size of the largest string in the JSON). It seems most C JSON libraries suck in some significant way: broken string support (what if the string contains \u0000?), broken/missing Unicode support, or crappy software license (GPL or "do no evil"). This library intends to avoid these flaws.
https://github.com/skeeto/pdjson
Description : a header-file-only, JSON parser serializer in C++
https://github.com/kazuho/picojson
Description : Lightweight, extremely high-performance JSON parser for C++11
https://github.com/chadaustin/sajson
Description : This is a simple, one-file JSON parser in C. It is designed for highly resource-constrained systems. It uses no memory allocation, and can stream data, so that the whole file does not need to reside in memory.
https://github.com/DagAgren/SmallJSONParser
Description : C++ universal value object and JSON library
https://github.com/jgarzik/univalue
Upvotes: 1