json-kotlin-pointer
Kotlin implementation of JavaScript Object Notation (JSON) Pointer.
Quick Start
This library uses the JSON classes from the jsonutil library. The examples below assume the existence of a JSONObject
similar to the one created as follows:
val json = JSON.parseObject("""{"list":[{"aaa":1},{"aaa":2}]}""")
To create a JSON Pointer from a string:
val pointer = JSONPointer("/list/0")
This pointer selects the property named "list" from the object, and then selects the first itemfrom the array.
To use the pointer, all of the following three forms are equivalent:
val result = pointer.eval(json)
val result = json locate pointer
val result = json locate "/list/0"
In each case, result
will contain the JSONObject
representing the nested object:
{"aaa":1}
More information to follow.
Dependency Specification
The latest version of the library is 0.3, and it may be obtained from the Maven Central repository.
Maven
<dependency>
<groupId>net.pwall.json</groupId>
<artifactId>json-kotlin-pointer</artifactId>
<version>0.3</version>
</dependency>
Gradle
implementation 'net.pwall.json:json-kotlin-pointer:0.3'
Gradle (kts)
implementation("net.pwall.json:json-kotlin-pointer:0.3")
Peter Wall
2020-09-16