1# <small>nlohmann::</small>operator""_json 2 3```cpp 4json operator ""_json(const char* s, std::size_t n); 5``` 6 7This operator implements a user-defined string literal for JSON objects. It can be used by adding `#!cpp _json` to a 8string literal and returns a [`json`](json.md) object if no parse error occurred. 9 10It is recommended to bring the operator into scope using any of the following lines: 11```cpp 12using nlohmann::literals::operator ""_json; 13using namespace nlohmann::literals; 14using namespace nlohmann::json_literals; 15using namespace nlohmann::literals::json_literals; 16using namespace nlohmann; 17``` 18 19This is suggested to ease migration to the next major version release of the library. See 20['JSON_USE_GLOBAL_UDLS`](macros/json_use_global_udls.md#notes) for details. 21 22## Parameters 23 24`s` (in) 25: a string representation of a JSON object 26 27`n` (in) 28: length of string `s` 29 30## Return value 31 32[`json`](json.md) value parsed from `s` 33 34## Exceptions 35 36The function can throw anything that [`parse(s, s+n)`](basic_json/parse.md) would throw. 37 38## Complexity 39 40Linear. 41 42## Examples 43 44??? example 45 46 The following code shows how to create JSON values from string literals. 47 48 ```cpp 49 --8<-- "examples/operator_literal_json.cpp" 50 ``` 51 52 Output: 53 54 ```json 55 --8<-- "examples/operator_literal_json.output" 56 ``` 57 58## Version history 59 60- Added in version 1.0.0. 61- Moved to namespace `nlohmann::literals::json_literals` in 3.11.0. 62