You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
If Replace operation is performed on JSON that doesn't have specified fields, these fields are added to JSON
To Reproduce
Code to reproduce the problem
using System;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;
using Json.Patch;
using Json.Pointer;
const string mask = "*****";
var maskJson = JsonValue.Create(mask);
var pathsToPatch = new[] { "/first_name", "/last_name" };
var patchOperations = pathsToPatch.Select(path => PatchOperation.Replace(JsonPointer.Parse(path), maskJson));
var patchConfig = new JsonPatch(patchOperations);
const string singleObjectJson =
"{\"id\":\"640729d45434f90313d25c78\",\"guid\":\"f2e2767c-03e0-4862-addc-7d46c55efb33\",\"city\":\"Boston\"}";
var singleObject = JsonNode.Parse(singleObjectJson);
var patchedSingleObject = patchConfig.Apply(singleObject).Result;
Console.WriteLine(JsonSerializer.Serialize(patchedSingleObject));
// ^ outputs {"id":"640729d45434f90313d25c78","guid":"f2e2767c-03e0-4862-addc-7d46c55efb33","city":"Boston","first_name":"*****","last_name":"*****"}
Expected behavior
Nothing changes in JSON
Considering that https://jsonpatch.com/ says that Replace equals to Remove and Add, I assume Remove result should be checked before adding the new fields
The text was updated successfully, but these errors were encountered:
So I've just checked that and found out that the RFC6902 notation explicitly says that The target location MUST exist for the operation to be successful.
I've also tried it out using online tools and JS libraries. https://jsonpatch.me/ silently returns unmodified JSON.
Both jsonpatch.js and jsonpatch-js throw an error about missing value.
Environment
Describe the bug
If
Replace
operation is performed on JSON that doesn't have specified fields, these fields are added to JSONTo Reproduce
Code to reproduce the problem
Expected behavior
Nothing changes in JSON
Considering that https://jsonpatch.com/ says that
Replace
equals toRemove
andAdd
, I assumeRemove
result should be checked before adding the new fieldsThe text was updated successfully, but these errors were encountered: