Created
May 27, 2024 21:08
-
-
Save azazellj/1cb87b424bb2a0123ceb1af2f8bb9e30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun searchTypeTokens( | |
jsonObject: JSONObject, | |
parentKey: String, | |
result: MutableMap<String, T>, | |
) { | |
for (key in jsonObject.keys()) { | |
// 'medium - prominent' to 'mediumProminent' | |
val keyFormatted = key.replace(" ", "").split("-").joinToString( | |
separator = "", | |
transform = { it.capitalized().trim() }, | |
) | |
val fullKey = if (parentKey.isEmpty()) key else "$parentKey$keyFormatted" | |
when (val value = jsonObject.get(key)) { | |
is JSONObject -> { | |
if (isTypeToken(value)) { | |
result[fullKey] = convert(field = value) | |
continue | |
} | |
searchTypeTokens(value, fullKey, result) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment