I am trying to find the solution for transforming the below JSON data. Mainly I want the date which is having ‘/’ to be replaced with ‘-‘.
The replace logic which I tried below is not working. Can someone help me in this?
It seems like replace with "modify-overwrite-beta’ is not working.
Input JSON
{
"certificates": [
{
"name": "name1",
"description": "description1",
"mapping": [
{
"date": "DEC/2023",
"code": "ABC1",
"rating": null,
"scope": [
"scope1",
"scope2",
"scope3"
]
}
]
},
{
"name": "name2",
"description": "description2",
"mapping": [
{
"date": null,
"code": "ABC1",
"rating": null,
"scope": [
"TBD"
]
}
]
}
]
}
Expected output:
{
"certificates" : [ {
"name" : "name1",
"description" : "description1",
"validity" : "DEC-2023",
"code" : "ABC1",
"rating" : null,
"scope" : [ "scope1", "scope2", "scope3" ]
}, {
"name" : "name2",
"description" : "description2",
"validity" : null,
"code" : "ABC1",
"rating" : null,
"scope" : [ "TBD" ]
} ],
"code" : "ABC1"
}
Tried the below spec
[
{
"operation": "shift",
"spec": {
"certificates": {
"*": {
"name": "certificates[&1].name",
"description": "certificates[&1].description",
"mapping": {
"*": {
"*": "certificates[&3].&",
"date": "certificates[&3].validity"
}
}
}
}
}
}, {
"operation": "default",
"spec": {
"code": "ABC1"
}
}, {
"operation": "modify-overwrite-beta",
"spec": {
"certificates": {
"*": {
"validity": "=replace(validity,'/','-')"
}
}
}
}
]
Getting below output
2
Answers
Hope the below Jolt Spec will be helpful for you.
Yet, you can use modify-overwrite-beta transformation along with split and join functions such as :
the demo on the site https://jolt-demo.appspot.com/ is :