I have a JSON input :
{
"levelOne": [
{
"leveltwo": {
"levelThree": [
{
"type": "typeOne",
"leveltwo": {
"Id": "101000094794",
"Id2": "101000013207"
}
},
{
"type": "typeTwo",
"leveltwo": {
"Id": "101000013207",
"Id2": "101000013207"
}
}
]
}
}
]
}
Is there a jolt spec that would lowercase every key, including keys in nested objects? (in this case what is under leveltwo)
{
"levelone": [
{
"leveltwo": {
"levelThree": [
{
"id": "101000094794",
"id2": "101000013207",
"type": "typeOne"
},
{
"id": "101000013207",
"id2": "101000013207",
"type": "typeTwo"
}
]
}
}
]
}
Currently, I’m using following spec (jolt template):`
[
{
"operation": "shift",
"spec": {
"levelOne": {
"*": {
"leveltwo": {
"id": "&3[&2].leveltwo.id",
"levelThree": {
"*": {
"leveltwo": {
"Id": "&6[&5].leveltwo.&3[&2].id",
"Id2": "&6[&5].leveltwo.&3[&2].id2"
},
"type": "&5[&4].leveltwo.&2[&1].type"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"$": "&1.key",
"@": "&1.value"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"levelOne": {
"key": "=toLower"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"value": "@(1,key)"
}
}
}
]
Expected result (key should be in lower levelThree, typeOne, typeTwo):
{
"levelone": [
{
"leveltwo": {
"levelthree": [
{
"id": "101000094794",
"id2": "101000013207",
"type": "typeone"
},
{
"id": "101000013207",
"id2": "101000013207",
"type": "typetwo"
}
]
}
}
]
}
Thanks!
3
Answers
Hi Priyanka this spec will resolve your issue. You can use =toLower case function in modify-overwrite-beta operation.
You can repeatedly apply the consecutive
shift
–modify
–shift
trio per each object key(levelOne
andlevelThree
in this case) which needs a case conversion such asAnother approach might be as follows :
You can be sure about all things to be lower with this jolt spec. You can modify each
location
,keys
, orvalues
in themodify
step.Please run each spec to see what happened.
Note: If you want to prevent to lower your values you can change this line
keys|values|location
in themodify
, to thiskeys|location
.