Crow has built in support for JSON data.
The types of values that
rvalue and wvalue can take are as follows:
False: from type
True: from type
Floating_point: from type
Signed_integer: from type
Unsigned_integer: from type
String: from type
List: from type
Object: from type
crow::json::wvalue or crow::json::rvalue.
This last type means that
rvalue or wvaluecan have keys.
JSON read value, used for taking a JSON string and parsing it into
You can read individual items of the rvalue, but you cannot add items to it.
To do that, you need to convert it to a
wvalue, which can be done by simply writing
crow::json::wvalue wval (rval); (assuming
rval is your
For more info on read values go here.
JSON write value, used for creating, editing and converting JSON to a string.
wvalue to object type can be done by simply assigning a value to whatever string key you like, something like
wval["key1"] = val1;. Keep in mind that val1 can be any of the above types.
wvalue can be treated as an object or even a list (setting a value by using
json = 32 for example). Please note that this will remove the data in the value if it isn't of List type.
An object type
std::unordered_map by default, if you want to have your returned
wvalue key value pairs be sorted (using
std::map) you can add
#define CROW_JSON_USE_MAP to the top of your program.
wvalue can be returned directly inside a route handler, this will cause the
content-type header to automatically be set to
Application/json and the JSON value will be converted to string and placed in the response body. For more information go to Routes.
For more info on write values go here.
Crow's json exceptions can be disabled by using the
#define CROW_JSON_NO_ERROR_CHECK macro. This should increase the program speed with the drawback of having unexpected behavious when used incorrectly (e.g. by attempting to parse an invalid json object).