How to flatten the output? #1102
Answered
by
HT154
nocquidant
asked this question in
Q&A
-
Hi, I'd like to flatten my JSON output (of course I have some exceptions).
=>
|
Beta Was this translation helpful? Give feedback.
Answered by
HT154
Jun 20, 2025
Replies: 1 comment 4 replies
-
Here's a function that will flatten a specific key in an object and return it as a function flattenKey(obj: Map|Mapping|Dynamic|Typed, key: String): Map =
obj.toMap().remove(key) + (
obj.toMap().getOrNull(key)?.toMap()?.mapKeys((k, _) -> "\(key)_\(k)") ?? Map()
) You can either call this directly as-needed or use renderer converters to apply the transformation at render time to the appropriate classes/paths. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's another (probably over-engineered) way to go about this using annotations and reflection: