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
b9a39b38
Unverified
Commit
b9a39b38
authored
Jan 19, 2019
by
Niels Lohmann
Committed by
GitHub
Jan 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1434 from pboettch/develop
allow push_back() and pop_back() calls on json_pointer
parents
dffae108
9225cf2f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
2 deletions
+74
-2
include/nlohmann/detail/json_pointer.hpp
include/nlohmann/detail/json_pointer.hpp
+10
-1
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+10
-1
test/src/unit-json_pointer.cpp
test/src/unit-json_pointer.cpp
+54
-0
No files found.
include/nlohmann/detail/json_pointer.hpp
View file @
b9a39b38
...
@@ -97,7 +97,6 @@ class json_pointer
...
@@ -97,7 +97,6 @@ class json_pointer
return
res
;
return
res
;
}
}
private:
/*!
/*!
@brief remove and return last reference pointer
@brief remove and return last reference pointer
@throw out_of_range.405 if JSON pointer has no parent
@throw out_of_range.405 if JSON pointer has no parent
...
@@ -114,6 +113,16 @@ class json_pointer
...
@@ -114,6 +113,16 @@ class json_pointer
return
last
;
return
last
;
}
}
/*!
@brief remove and return last reference pointer
@throw out_of_range.405 if JSON pointer has no parent
*/
void
push_back
(
const
std
::
string
&
tok
)
{
reference_tokens
.
push_back
(
tok
);
}
private:
/// return whether pointer points to the root document
/// return whether pointer points to the root document
bool
is_root
()
const
noexcept
bool
is_root
()
const
noexcept
{
{
...
...
single_include/nlohmann/json.hpp
View file @
b9a39b38
...
@@ -11884,7 +11884,6 @@ class json_pointer
...
@@ -11884,7 +11884,6 @@ class json_pointer
return
res
;
return
res
;
}
}
private:
/*!
/*!
@brief remove and return last reference pointer
@brief remove and return last reference pointer
@throw out_of_range.405 if JSON pointer has no parent
@throw out_of_range.405 if JSON pointer has no parent
...
@@ -11901,6 +11900,16 @@ class json_pointer
...
@@ -11901,6 +11900,16 @@ class json_pointer
return
last
;
return
last
;
}
}
/*!
@brief remove and return last reference pointer
@throw out_of_range.405 if JSON pointer has no parent
*/
void
push_back
(
const
std
::
string
&
tok
)
{
reference_tokens
.
push_back
(
tok
);
}
private:
/// return whether pointer points to the root document
/// return whether pointer points to the root document
bool
is_root
()
const
noexcept
bool
is_root
()
const
noexcept
{
{
...
...
test/src/unit-json_pointer.cpp
View file @
b9a39b38
...
@@ -459,4 +459,58 @@ TEST_CASE("JSON pointers")
...
@@ -459,4 +459,58 @@ TEST_CASE("JSON pointers")
CHECK
(
j
.
is_object
());
CHECK
(
j
.
is_object
());
}
}
}
}
SECTION
(
"push and pop"
)
{
const
json
j
=
{
{
""
,
"Hello"
},
{
"pi"
,
3.141
},
{
"happy"
,
true
},
{
"name"
,
"Niels"
},
{
"nothing"
,
nullptr
},
{
"answer"
,
{
{
"everything"
,
42
}
}
},
{
"list"
,
{
1
,
0
,
2
}},
{
"object"
,
{
{
"currency"
,
"USD"
},
{
"value"
,
42.99
},
{
""
,
"empty string"
},
{
"/"
,
"slash"
},
{
"~"
,
"tilde"
},
{
"~1"
,
"tilde1"
}
}
}
};
// empty json_pointer returns the root JSON-object
auto
ptr
=
""
_json_pointer
;
CHECK
(
j
[
ptr
]
==
j
);
// simple field access
ptr
.
push_back
(
"pi"
);
CHECK
(
j
[
ptr
]
==
j
[
"pi"
]);
ptr
.
pop_back
();
CHECK
(
j
[
ptr
]
==
j
);
// object and children access
ptr
.
push_back
(
"answer"
);
ptr
.
push_back
(
"everything"
);
CHECK
(
j
[
ptr
]
==
j
[
"answer"
][
"everything"
]);
ptr
.
pop_back
();
ptr
.
pop_back
();
CHECK
(
j
[
ptr
]
==
j
);
// push key which has to be encoded
ptr
.
push_back
(
"object"
);
ptr
.
push_back
(
"/"
);
CHECK
(
j
[
ptr
]
==
j
[
"object"
][
"/"
]);
CHECK
(
ptr
.
to_string
()
==
"/object/~1"
);
}
}
}
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