Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
温绍锦 edited this page Jun 14, 2020 · 1 revision

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

API

packagecom.alibaba.fastjson;
publicclassJSONPatch {
publicstaticStringapply(Stringoriginal, Stringpatch);
publicstaticObjectapply(Objectobject, Stringpatch);
}

DEMO

Stringoriginal = "{\n" +
" \"baz\": \"qux\",\n" +
" \"foo\": \"bar\"\n" +
"}";
Stringpatch = "[\n" +
" { \"op\": \"replace\", \"path\": \"/baz\", \"value\": \"boo\" },\n" +
" { \"op\": \"add\", \"path\": \"/hello\", \"value\": [\"world\"] },\n" +
" { \"op\": \"remove\", \"path\": \"/foo\" }\n" +
"]";
Stringresult = JSONPatch.apply(original, patch);
assertEquals("{\"baz\":\"boo\",\"hello\":[\"world\"]}", result);

Clone this wiki locally