Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
293cd6b7
Commit
293cd6b7
authored
6 years ago
by
Macr0Nerd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added to_string and added basic tests
parent
ee4028b8
develop
bon8
coverity_scan
feature/optional
gcc_warning_flags
icpc
issue2228
issue2615
issue2932
issue3232_use_catch
master
release/3.10.2
release/3.10.3
release/3.10.4
release/3.10.5
string_view
string_view2
update_doctest
v3.10.5
v3.10.4
v3.10.3
v3.10.2
v3.10.1
v3.10.0
v3.9.1
v3.9.0
v3.8.0
v3.7.3
v3.7.2
v3.7.1
v3.7.0
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
0 deletions
+43
-0
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+14
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+14
-0
test/src/unit-serialization.cpp
test/src/unit-serialization.cpp
+15
-0
No files found.
include/nlohmann/json.hpp
View file @
293cd6b7
...
@@ -7965,6 +7965,20 @@ class basic_json
...
@@ -7965,6 +7965,20 @@ class basic_json
/// @}
/// @}
};
};
/*!
@brief user-defined to_string function for JSON values
This function implements a user-defined to_string for JSON objects.
@param[in] j a JSON object
@return a std::string object
*/
template
<
class
T
>
std
::
string
to_string
(
const
T
&
j
){
return
j
.
dump
();
}
}
// namespace nlohmann
}
// namespace nlohmann
///////////////////////
///////////////////////
...
...
This diff is collapsed.
Click to expand it.
single_include/nlohmann/json.hpp
View file @
293cd6b7
...
@@ -20766,6 +20766,20 @@ class basic_json
...
@@ -20766,6 +20766,20 @@ class basic_json
/// @}
/// @}
};
};
/*!
@brief user-defined to_string function for JSON values
This function implements a user-defined to_string for JSON objects.
@param[in] j a JSON object
@return a std::string object
*/
template
<
class
T
>
std
::
string
to_string
(
const
T
&
j
){
return
j
.
dump
();
}
}
// namespace nlohmann
}
// namespace nlohmann
///////////////////////
///////////////////////
...
...
This diff is collapsed.
Click to expand it.
test/src/unit-serialization.cpp
View file @
293cd6b7
...
@@ -173,4 +173,19 @@ TEST_CASE("serialization")
...
@@ -173,4 +173,19 @@ TEST_CASE("serialization")
test
(
"
\xE1\x80\xE2\xF0\x91\x92\xF1\xBF\x41
"
,
"
\\
ufffd"
"
\\
ufffd"
"
\\
ufffd"
"
\\
ufffd"
"
\x41
"
);
test
(
"
\xE1\x80\xE2\xF0\x91\x92\xF1\xBF\x41
"
,
"
\\
ufffd"
"
\\
ufffd"
"
\\
ufffd"
"
\\
ufffd"
"
\x41
"
);
}
}
}
}
SECTION
(
"to_string"
)
{
auto
test
=
[
&
](
std
::
string
const
&
input
,
std
::
string
const
&
expected
)
{
using
std
::
to_string
;
json
j
=
input
;
CHECK
(
to_string
(
j
)
==
"
\"
"
+
expected
+
"
\"
"
);
};
test
(
"{
\"
x
\"
:5,
\"
y
\"
:6}"
,
"{
\\\"
x
\\\"
:5,
\\\"
y
\\\"
:6}"
);
test
(
"{
\"
x
\"
:[10,null,null,null]}"
,
"{
\\\"
x
\\\"
:[10,null,null,null]}"
);
test
(
"test"
,
"test"
);
test
(
"[3,
\"
false
\"
,false]"
,
"[3,
\\\"
false
\\\"
,false]"
);
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment