Simple implementation of RFC 6902 JSON Patch written in kotlin.
This is a simple implementation of RFC 6902 written in Kotlin, which uses kotlinx-serializationas its core. It can only apply JsonPatch to JsonElement, it doesn't support diff or generating JsonPatch, if you need it try zjsonpatch or json-patch.
Generates some test patches using fast-json-patch.
- add
- remove
- replace
- move
- copy
// object element
val element = Json.parseToJsonElement("{\"name\": \"John\"}")
val operation = JsonPatchOperation("add", "/age", JsonPrimitive(30))
val modifiedElement = JsonPatch(listOf(operation)).applyPatch(element)
println(modifiedElement) // {"name":"John","age":30}
// array element
val element = Json.parseToJsonElement("[\"apple\"]")
val operation = JsonPatchOperation("add", "/1", JsonPrimitive("banana"))
val modifiedElement = JsonPatch(listOf(operation)).applyPatch(element)
println(modifiedElement) // ["apple","banana"]