Skip to content

Instantly share code, notes, and snippets.

@azazellj
Created May 27, 2024 21:08
Show Gist options
  • Save azazellj/1cb87b424bb2a0123ceb1af2f8bb9e30 to your computer and use it in GitHub Desktop.
Save azazellj/1cb87b424bb2a0123ceb1af2f8bb9e30 to your computer and use it in GitHub Desktop.
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