Giter Site home page Giter Site logo

Comments (4)

gregmarr avatar gregmarr commented on May 26, 2024 1

Your sample JSON is invalid. It contains an unmatched ].

, } ], "xyz" : [ { "

Removing the }] makes it parsable.

from json.

gregmarr avatar gregmarr commented on May 26, 2024

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.

sujayran avatar sujayran commented on May 26, 2024

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.

gregmarr avatar gregmarr commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.