Skip to content

Commit f4bc90b

Browse files
committed
Merge branch 'dev'
2 parents cfc3e7a + 614e4ec commit f4bc90b

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

include/vix/json/json.hpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,27 @@ namespace vix::json
119119
inline Json arr() { return Json::array(); }
120120

121121
/**
122-
* @brief JSON string literal helpers from nlohmann.
122+
* @brief JSON string literal helpers.
123123
*
124124
* Enables:
125125
* @code
126+
* #define VIX_JSON_ENABLE_LITERALS 1
126127
* using namespace vix::json::literals;
127128
* Json j = R"({"a": 1, "b": 2})"_json;
128129
* @endcode
130+
*
131+
* Note:
132+
* Disabled by default because it relies on parsing (can throw).
129133
*/
130-
#if defined(NLOHMANN_JSON_VERSION_MAJOR)
131-
#if (NLOHMANN_JSON_VERSION_MAJOR > 3) || \
132-
(NLOHMANN_JSON_VERSION_MAJOR == 3 && NLOHMANN_JSON_VERSION_MINOR >= 10)
133-
namespace literals = nlohmann::literals::json_literals;
134-
#endif
134+
namespace literals
135+
{
136+
#if defined(VIX_JSON_ENABLE_LITERALS) && (VIX_JSON_ENABLE_LITERALS == 1)
137+
inline Json operator"" _json(const char *s, std::size_t n)
138+
{
139+
return Json::parse(std::string_view{s, n});
140+
}
135141
#endif
142+
} // namespace literals
136143

137144
} // namespace vix::json
138145

include/vix/json/loads.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace vix::json
146146
try
147147
{
148148
Json j = Json::parse(s);
149-
return j;
149+
return std::optional<Json>{std::move(j)};
150150
}
151151
catch (...)
152152
{

0 commit comments

Comments
 (0)