This is my first time using Jolt and I am amazed at transformations it can perform. I followed the documentation and few posts online.
However, I am still have challenges with:
- concatenating new values to existing values (url in this case)
- moving concatenated value to right place
- adding a default key-value pair if it doesn't exist in input JSON
- Assigning JSON object to correct JSON array.
I have the following input
{
"Body": [
{
"username": "some-user"
},
{
"password": "*******"
}
],
"hostSource": "infos",
"Host": [
{
"HOST_NAME": "xyz.com"
},
{
"PORT": "9085"
}
],
"Headers": [
{
"Content-Type": "application/json"
}
]
}
and my expected output is:
{
"templateConfig": {
"commonClientConfig ": {
"item": [
{
"name": "Main API - BASICAUTH",
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "*******",
"type": "string"
},
{
"key": "username",
"value": "some-user",
"type": "string"
}
]
},
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"url": {
"raw": "xyz.com/v9085/some-default-value"
}
}
}
]
}
}
}
After referring few posts and documentation, I was able to get this far with the spec:
[
{
"operation": "shift",
"spec": {
"Body": {
"*": {
"*": {
"$": "commonClientConfig.item.request.auth.basic[&2].key",
"@(1,&)": "commonClientConfig.item.request.auth.basic[&2].value"
}
}
},
"Headers": {
"*": {
"*": {
"$": "commonClientConfig.item.request.header[&2].key",
"@(1,&)": "commonClientConfig.item.request.header[&2].value"
}
}
},
"Host": {
"*": {
"*": {
"@(1,&)": "commonClientConfig.item.request.url.raw"
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"content": "=join('/', @(2,commonClientConfig.item.request.url.raw))"
}
}
]
I would really appreciate if someone can provide some guidance here with explanation.