private JsonPatchResult _Remove(JsonValue json)
        {
            if (string.IsNullOrEmpty(Path))
            {
                json.Object.Clear();
                return(new JsonPatchResult(json));
            }

            var(target, key, index, found) = JsonPointerFunctions.ResolvePointer(json, Path);
            if (!found)
            {
                return(new JsonPatchResult(json, $"Path '{Path}' not found."));
            }

            switch (target.Type)
            {
            case JsonValueType.Object:
                target.Object.Remove(key);
                break;

            case JsonValueType.Array:
                target.Array.RemoveAt(index);
                break;

            default:
                return(new JsonPatchResult(json, $"Cannot remove a value from a '{target.Type}'"));
            }

            return(new JsonPatchResult(json));
        }
        private JsonPatchResult _Add(JsonValue json)
        {
            var(result, success) = JsonPointerFunctions.InsertValue(json, Path, Value);

            if (!success)
            {
                return(new JsonPatchResult(json, "Could not add the value"));
            }

            return(new JsonPatchResult(result));
        }
Example #3
0
        private JsonPatchResult _Test(JsonValue json)
        {
            var value = JsonPointerFunctions.RetrieveValue(json, Path);

            if (ReferenceEquals(value, null))
            {
                return(new JsonPatchResult(json, $"The path '{Path}' does not exist."));
            }

            if (value != Value)
            {
                return(new JsonPatchResult(json, $"The value at '{Path}' is not the expected value."));
            }

            return(new JsonPatchResult(json));
        }
        private JsonPatchResult _RemoveAtPath(JsonValue json, string path)
        {
            if (string.IsNullOrEmpty(Path))
            {
                json.Object.Clear();
                return(new JsonPatchResult(json));
            }

            var(target, key, index, found) = JsonPointerFunctions.ResolvePointer(json, path);
            if (!found)
            {
                return(new JsonPatchResult(json, $"Path '{path}' not found."));
            }

            switch (target !.Type)
            {
        private JsonPatchResult _Copy(JsonValue json)
        {
            var results = JsonPointer.Parse(From).Evaluate(json);

            if (results.Error != null)
            {
                return(new JsonPatchResult(json, results.Error));
            }

            var(result, success) = JsonPointerFunctions.InsertValue(json, Path, results.Result);
            if (!success)
            {
                return(new JsonPatchResult(json, "Could not add the value"));
            }

            return(new JsonPatchResult(result));
        }
Example #6
0
        private JsonPatchResult _Copy(JsonValue json)
        {
            var value = JsonPointerFunctions.RetrieveValue(json, From);

            if (ReferenceEquals(value, null))
            {
                return(new JsonPatchResult(json, $"The path '{Path}' does not exist."));
            }

            var(result, success) = JsonPointerFunctions.InsertValue(json, Path, value);
            if (!success)
            {
                return(new JsonPatchResult(json, "Could not add the value"));
            }

            return(new JsonPatchResult(result));
        }