Skip to content

sum1re/json-patch

Repository files navigation

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.

Support operations:

  • add
  • remove
  • replace
  • move
  • copy

Sample usage

// 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"]

About

Simple implementation of JSON Patch

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages