I have json response where only just one key name change rest is same and want to parse without duplicating same struct again.
"attributes": {
"symbol":"EUR",
"name":"Euro",
"precision":2,
}
"attributes":{
"symbol":"EUR",
"name":"Euro",
"precision_for_fiat_price":2,
}
How can handle this precision key dynamically in json parsing
You can use a custom
keyDecodingStrategy
.Essentially, you write some logic that checks whether the current coding key path matches some criteria, and if it does, map that key to the
precision
key.For example: