News for hackers. Stuff that matters.
Re:What Is JSON Patch? by masklinn on Tuesday May 10, 2022 @02:47AM (#31324229)
And how do you set a field to null?
Re:What Is JSON Patch? by HWR_14 on Tuesday May 10, 2022 @10:40AM (#31327683)
To delete something, I imagine you set it to undefined. I don't know anyone who uses the undefined state at rest for anything interesting.
Re:What Is JSON Patch? by anentropic on Tuesday May 10, 2022 @11:03AM (#31327964)
JSON doesn't have undefined, only null

the partial updates approach works ok for updating 'schemaful' data, where it could only ever mean to set the field to null and could never delete the field from the object altogether

but for editing a JSON document or other schemaless data then both operations are possible and you'd need to be able to distinguish them

Re:What Is JSON Patch? by jayd16 on Tuesday May 10, 2022 @02:47AM (#31324234)
Same way.
Re:What Is JSON Patch? by masklinn on Tuesday May 10, 2022 @06:03AM (#31325307)
So you set a field to `null` using

    { "foo": null }
and you delete a field using

    { "foo": null }
don't you see a bit of an issue there?
Re:What Is JSON Patch? by chii on Tuesday May 10, 2022 @03:21AM (#31324457)
as in `{null:null}` ?

won't that set a field called 'null', to the value null?

Re:What Is JSON Patch? by jayd16 on Tuesday May 10, 2022 @03:37AM (#31324529)
As in { "foo" : null }

You can interpret a null field the same as a missing field. You only need to worry if you have arbitrary dictionary keys and need to differentiate a null value from an missing key.

Re:What Is JSON Patch? by masklinn on Tuesday May 10, 2022 @06:05AM (#31325317)
> You can interpret a null field the same as a missing field.

Not in the general case no, they are two different states, which may have entirely different semantics.

For instance a missing field can mean "don't touch this field" while a field set to null means "set this field to null".

Some schemas might opt to ignore this distinction and collapse the states, but that is a specific decision, and an express loss of information.

> You only need to worry if you have arbitrary dictionary keys and need to differentiate a null value from an missing key.

There are other situations where that's an issue, like the above, or when you're using the object as a set (which JSON doesn't have), or when you've defined the schema to never have missing fields (but possibly have some set to `null`) so clients will break, ...

Re:What Is JSON Patch? by rrrhys on Tuesday May 10, 2022 @04:57AM (#31324953)
Null could imply the field was present and a value not entered or not necessary. Missing could imply the field was never known about at all. The context is important.

Null != missing.