Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help to create spec jolt transformers #1275

Open
alfamousts opened this issue Jan 17, 2025 · 1 comment
Open

help to create spec jolt transformers #1275

alfamousts opened this issue Jan 17, 2025 · 1 comment

Comments

@alfamousts
Copy link

Please help me to transform this Json
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"instance": "abc"
},
"values": [
[
1737087025,
"1449697924095"
],
[
1737087021,
"1449697924091"
]
]
},
{
"metric": {
"instance": "cab"
},
"values": [
[
1737087025,
"1449697924095"
],
[
1737087021,
"1449697924091"
]
]
}
]
}
}

into this output json
[ {
"instance":"abc",
"timestamp":1737087025
"value":"1449697924095"
},
{
"instance":"abc",
"timestamp":1737087021
"value":"1449697924091"
},
{
"instance":"cab",
"timestamp":1737087025
"value":"1449697924095"
},
{
"instance":"cab",
"timestamp":1737087021
"value":"1449697924091"
}
]

@LucaBiscotti
Copy link

Hi @alfamousts
The spec here is pretty simple:

 [
   {
     "operation": "shift",
     "spec": {
       "data": {
         "result": {
           "*": {
             "values": {
               "*": {
                 "@(2,metric.instance)": "&3.[&0].istance",
                 "@[0]": "&3.[&0].timestamp",
                 "@[1]": "&3.[&0].value"
               }
             }
           }
         }
       }
     }
    },
   {
     "operation": "shift",
     "spec": {
       "*": {
         "*": "[]"
       }
     }
    }
]

At first you go inside the values array and then, by doing: "@(2,metric.instance)" you are saying go up 2 and take wathever value there is in the metric.instance path. After that we take the element at index 0 and 1 of values.

The second spec is just for adjusting the output to be cleaner.

Hope I helped :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants