0

allign json elements

Hello Klipfolio Experts,

hopefully someone can help me.

I have the following json:

{
"objects":[
{
"event_service":[
{
"service":{
"service_name":"Service 1"
}
},
{
"service":{
"service_name":"Service 2"
}
}
],
"severity":{
"severity":"major"
}
},
{
"event_service":[
{
"service":{
"service_name":"Service 2"
}
}
],
"severity":{
"severity":"minor"
}
},
{
"event_service":[
{
"service":{
"service_name":"Service 2"
}
}
],
"severity":{
"severity":"minor"
}
}
]
}

The tricky thing here is that the first element of event_service has two child of service_name. The other has only one service_name.

I like to get now an allignment of severity and service name. Like this:

Service 1, Major

Service 2, Major

Service 2, Minor

Service 2, Minor

 

But unfortunately i have no idea which function should i use here.

 

Regards,

Torsten

4 comments

  • 0
    Avatar
    Janice Janczyn

    Hi Torsten,

    Klipfolio provides a few XPath methods to align JSON data, please see the About JSON and XML Datasources article for details. In your case, to repeat the severity for each event_service, you need to edit the XPath and insert the kf:fill_elements method. This requires some familiarity with XPath manipulation and again it is helpful to read the About JSON and XML Datasources article.

    1. select the object you need to have a value repeated for, in this case, @/objects/event_service/service/service_name;
    2. double-click the XPath to edit, then delete the XPath until you reach the array: @/objects/event_service;
    3. "back up" (/..) the XPath to the same level as the value you need to repeat: @/objects/event_service/..;
    4. insert 'kf:fill_elements' (without the quotes) after the @  and add the path to the object you want to repeat (/severity/severity) using the specified notation (each level is listed as a separate parameter in single quotes):

                        @kf:fill_elements( /objects/event_service/.., 'severity', 'severity' );

    I hope this helps. If you have further questions, please email support@klipfolio.com.

    Thank you,
                 Janice

  • 0
    Avatar
    Torsten Reschke

    Thanks a lot ! I solved my issue.

  • 0
    Avatar
    Lars Skjoldby

    Hi Thorsten,

    Looking for the exact same solutions and I have tried Janice' suggestion. However, something doesn't work in my setup - I'm doing something wrong.

    Are you able to post some screenshots of your setup after you've applied Janice suggestion?

  • 0
    Avatar
    Torsten Reschke

    Hi Lars,

    maybe this screenshot helps a little bit:

    Regards,

    Torsten

Please sign in to leave a comment.