Comments (4)
Your sample JSON is invalid. It contains an unmatched ]
.
, } ], "xyz" : [ { "
Removing the }]
makes it parsable.
from json.
Your operation is invalid according to JSON Patch. Previous versions of the library erroneously accepted it. That was fixed in #3628
https://datatracker.ietf.org/doc/html/rfc6902#page-4
When the operation is applied, the target location MUST reference one of:
- A member to add to an existing object - whereupon the supplied
value is added to that object at the indicated location. If the
member already exists, it is replaced by the specified value. - An element to add to an existing array - whereupon the supplied
value is added to the array at the indicated location. Any
elements at or above the specified index are shifted one position
to the right. The specified index MUST NOT be greater than the
number of elements in the array. If the "-" character is used to
index the end of the array (see [RFC6901]), this has the effect of
appending the value to the array.
Your location is neither an existing object, nor an array element, but instead a location inside a non-existing object. You need to add the full new element as a single operation, or add an empty element and then add members to it.
from json.
Thank for the reply, if i understand this right, you are saying its failing due to the fact that at location of array element 1 we don't have lmn "/xyz/1/lmn" ?
{
"op" : "add",
"path" : "/xyz/1",
"value" : ""
}, {
"op" : "add",
"path" : "/xyz/1/lmn",
"value" : "214"
}, {
"op" : "add",
"path" : "/xyz/1/nnp",
"value" : "002"
}
/usr/json-3.11.3/include/nlohmann/json.hpp:4799: auto nlohmann::basic_json<>::patch_inplace(const basic_json<> &)::(anonymous class)::operator()(json_pointer &, basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>) const [ObjectType = std::map, ArrayType = std::vector, StringType = std::basic_string, BooleanType = bool, NumberIntegerType = long, NumberUnsignedType = unsigned long, NumberFloatType = double, AllocatorType = std::allocator, JSONSerializer = nlohmann::adl_serializer, BinaryType = std::vector, CustomBaseClass = void]: Assertion `false' failed.
from json.
It's because /xyz/1
doesn't exist. You need to create /xyz/1
before you can add more things to it. What you have there is should be close to working but I think "value": ""
would make it a string instead of an object. Can you try "value": {}
instead?
Another way would be
{
"op" : "add",
"path" : "/xyz/1",
"value" : { "lmn": "214", "nnp": "002" }
}
from json.
Related Issues (20)
- stack overflow while fuzzing parse-cbor-fuzzer HOT 3
- NLOHMANN_JSON_FROM* macros not comptaible with non-default-constructible types HOT 6
- Parsing simple zeroes throws type exception HOT 1
- Newer serialization macros not listed in README
- Cannot use std::format on nholman::json objects HOT 8
- to_json(std::filesystem::path) can create invalid UTF-8 chars on windows HOT 2
- Parsing the unicode string got the wrong result HOT 7
- Can't run `make amalgamate` HOT 1
- JSON parses as array when assigned in initializer list. HOT 1
- Program crashes with ordered_json, but works fine with json HOT 5
- Simple example with nlohmann::ordered_json doesn't compile HOT 2
- Segfault on parse when using "#pragma pack (push, 1)" HOT 4
- Incorrect floating point parsing HOT 2
- ordered json pointer corruption HOT 5
- Validatable release artifacts are not sufficient for packaging (trying to run tests) HOT 8
- Assertion failed when accessing non-existing object with const json object HOT 12
- Inconsistent behaviour of json construction using `std::initializer_list` HOT 1
- CBOR data cannot be decoded HOT 3
- Docs have incorrect info for `update()`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json.