Skip to content

Commit 64aee4b

Browse files
committed
Write json.md content
1 parent c49ec34 commit 64aee4b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

doc/json.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Converting to/from JSON
2+
3+
## `graphqljson` Library Target
4+
5+
Converting between `graphql::response::Value` in [GraphQLResponse.h](../include/GraphQLResponse.h)
6+
and JSON strings is done in an optional library target called `graphqljson`.
7+
8+
## Default RapidJSON Implementation
9+
10+
The included implementation uses [RapidJSON](https://github.com/Tencent/rapidjson)
11+
release 1.1.0, but if you don't need JSON support, or you want to integrate
12+
a different JSON library, you can set `GRAPHQL_USE_RAPIDJSON=OFF` in your
13+
CMake configuration.
14+
15+
## Using Custom JSON Libraries
16+
17+
If you want to use a different JSON library, you can add implementations of
18+
the functions in [JSONResponse.h](../include/JSONResponse.h):
19+
```cpp
20+
namespace graphql::response {
21+
22+
std::string toJSON(Value&& response);
23+
24+
Value parseJSON(const std::string& json);
25+
26+
} /* namespace graphql::response */
27+
```
28+
29+
You will also need to update the [CMakeLists.txt](../src/CMakeLists.txt) file
30+
in the [../src](../src) directory to add your own implementation. See the
31+
comment in that file for more information:
32+
```cmake
33+
# RapidJSON is the only option for JSON serialization used in this project, but if you want
34+
# to use another JSON library you can implement an alternate version of the functions in
35+
# JSONResponse.cpp to serialize to and from GraphQLResponse and build graphqljson from that.
36+
# You will also need to define how to build the graphqljson library target with your
37+
# implementation, and you should set BUILD_GRAPHQLJSON so that the test dependencies know
38+
# about your version of graphqljson.
39+
option(GRAPHQL_USE_RAPIDJSON "Use RapidJSON for JSON serialization." ON)
40+
```

0 commit comments

Comments
 (0)