generated from arrow-kt/Arrow-KMP-Template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-readme-04.kt
39 lines (35 loc) · 1.02 KB
/
example-readme-04.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// This file was automatically generated from README.md by Knit tool. Do not edit.
@file:Suppress("InvalidPackageDeclaration")
package com.example.exampleReadme04
import kotlinx.serialization.*
import kotlinx.serialization.json.*
import arrow.optics.*
import io.github.nomisrev.*
import arrow.optics.typeclasses.*
private const val JSON_STRING = """
{
"name": "Arrow",
"address": {
"city": "Functional Town",
"street": {
"number": 1337,
"name": "Functional street"
}
},
"employees": [
{
"name": "John",
"lastName": "doe"
},
{
"name": "Jane",
"lastName": "doe"
}
]
}"""
fun main(): Unit {
val json: JsonElement = Json.decodeFromString(JSON_STRING)
val employeesName: Traversal<JsonElement, String> = JsonPath.pathEvery("employees.*.name").string
val res: JsonElement = employeesName.modify(json, String::uppercase).also(::println)
employeesName.getAll(res).also(::println)
}