Find same (key, value) pair in other localization json-file
Answered
Hello, I want to find the same (key,value) pair in an other json localization file. My json looks like this.
{
"general": {
"main": {
"title": "This is a title",
"header": "This is a header",
"sub": {
"sub_thing_1": "Something",
"sub_thing_2": "Something2"
}
}
},
"other_things": {
"title": "Other title"
"sub": {
"sub_thing_1": "Something",
"sub_thing_2": "Something2"
}
}
}
My thinking is, to generate a collection that contains, the depth values like this
eg: the "sub_thing_2" can be found at -> ["general", "main", "sub"]
and with this information i can find the exact key in other files.
And with this code I geathering the depth information for each (key value) pair, this is just a scratch, thinkering code fragement, I'm new to Kotlin
psi?.accept(object : JsonRecursiveElementVisitor() {
override fun visitObject(o: JsonObject) {
val childrens = o.children
for (child in childrens) {
val childProp = child as JsonProperty
if (child.lastChild is JsonObject) {
depth.add(childProp.name)
visitObject(child.lastChild as JsonObject)
} else {
println(depth.toString() + childProp.name + ": " + childProp.lastChild.text)
}
}
if (depth.isNotEmpty()) {
val lastItem = depth.last();
depth.remove(lastItem)
}
}
})
My question is there is other easier way to do this or I'm in the right direction?
Please sign in to leave a comment.
Looks like going in the right direction IMHO
Thank you!