Code Monkey home page Code Monkey logo

Comments (6)

apelisse avatar apelisse commented on September 15, 2024 1

@pacoxu In case it's not clear, I think we agree. Lists should be replaced without editing, i.e. nulls should be preserved. And yes, the spec doesn't have a single example with a null in a list.

from json-patch.

apelisse avatar apelisse commented on September 15, 2024

I'm not a lawyer :-), but here's how I read the spec:

  • Section 1, it's arguable whether this means that items in an array should be removed, especially since arrays are supposed to be strictly replaced.

Null values in the merge patch are given special meaning to indicate the removal of existing values in the target.

  • Section 2, the example algorithm replaces lists altogether with no changes, as expected:
define MergePatch(Target, Patch):
 if Patch is an Object:
   if Target is not an Object:
 Target = {} # Ignore the contents and set it to an empty Object
   for each Name/Value pair in Patch:
 if Value is null:
   if Name exists in Target:
     remove the Name/Value pair from Target
 else:
   Target[Name] = MergePatch(Target[Name], Value)
   return Target
 else:
   return Patch

from json-patch.

pacoxu avatar pacoxu commented on September 15, 2024

Thanks for your reply @apelisse.

I read the spec, examples from the spec like below.

ORIGINAL PATCH RESULT
{"a": [ {"b":"c"} ] } {"a": [1]} {"a": [1]}
["a","b"] ["c","d"] ["c","d"]
{"a":"foo"} null null
{"e":null} {"a":1} {"e":null, "a":1}
{} {"a": {"bb": {"ccc": null}}} {"a":{"bb": {}}}
{"a":"b"} {"a":"c"} {"a":"c"}
{"a":"b"} {"b":"c"} {"a":"b", "b":"c"}
{"a":"b"} {"a":null} {}
{"a":"b", "b":"c"} {"a":null} {"b":"c"}
{"a":["b"]} {"a":"c"} {"a":"c"}
{"a":"c"} {"a":["b"]} {"a":["b"]}
{"a":"b"} ["c"] ["c"]
{"a":"foo"} "bar" "bar"

Currently, we want to define examples for arrays with null values:

ORIGINAL PATCH Current RESULT RESULT without pruneNullInArray
{"a": [ {"b":"c"} ] } {"a": [1]} {"a": [1]} {"a": [1]}
{"a": [ {"b":"c"} ] } {"a": [null, 1]} {"a": [1]} {"a": [null, 1]}
["a",null] [null] [] [null]
["a"] [null] [] [null]
["a", "b"] ["a",null] ["a"] ["a",null]
{"a":["b"]} {"a": ["b", null]} {"a":["b"]} {"a":["b", null]}
{"a":[]} {"a": ["b", null, null, "a"]} {"a":["b", "a"]} {"a":["b", null, null, "a"]}

Also, it is not possible to
patch part of a target that is not an object, such as to replace just
some of the values in an array.

According to the rfc and the examples, we should not change the array. An array is an object as a whole.

from json-patch.

pacoxu avatar pacoxu commented on September 15, 2024

If this is arguable, an option for this would be necessary.

Let users decide which suits their scenarios.

spec:
  properties:
    allocations:
      items:
        nullable: true
        type: integer
      type: array

For Kubernetes custom resource defined property as type nullable=true array, nulls should be preserved.
For other cases, nulls may be pruned for purposes.

from json-patch.

apelisse avatar apelisse commented on September 15, 2024

I don't think we should ever drop nulls in arrays.

from json-patch.

pacoxu avatar pacoxu commented on September 15, 2024

@evanphx would you release a new version? Thanks.

We probably need to update the version of json-patch used in kubernetes now!

from json-patch.

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.