Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

JSONPatch

温绍锦 edited this page Jun 14, 2020 · 1 revision

在fastjson 1.2.71版本后,支持JSONPatch ( http://jsonpatch.com/ ).

API

package com.alibaba.fastjson;

public class JSONPatch {
     public static String apply(String original, String patch);
     public static Object apply(Object object, String patch);
}

DEMO

String original = "{\n" +
        "  \"baz\": \"qux\",\n" +
        "  \"foo\": \"bar\"\n" +
        "}";

String patch = "[\n" +
        "  { \"op\": \"replace\", \"path\": \"/baz\", \"value\": \"boo\" },\n" +
        "  { \"op\": \"add\", \"path\": \"/hello\", \"value\": [\"world\"] },\n" +
        "  { \"op\": \"remove\", \"path\": \"/foo\" }\n" +
        "]";

String result = JSONPatch.apply(original, patch);
assertEquals("{\"baz\":\"boo\",\"hello\":[\"world\"]}", result);
Clone this wiki locally