# JSON Path: extract same attributes for different objects

**URL:** <https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598>\
**Category:** KNIME Analytics Platform\
**Created:** [November 3, 2022, 1:56pm UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598 "2022-11-03T13:56:32Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![fseck](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/f/47e85d/32.png) [@fseck](https://forum.knime.com/u/fseck)\
**Post date:** [November 3, 2022, 1:56pm UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/1 "2022-11-03T13:56:32Z")

</div>

Hello everyone,

I want to extract certain information from a JSON file with Knime.  
I already figured out which nodes to use:  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/d/4/d42d2c47a537b9bacf81ee2fb198852414b4b3ea.png)

now I am stuck at the correct JSON path.  
The JSON structure has a repeating pattern for different outputs.  
I would like to get for example the attribute 1 from ,general data" and the third value of attribute 1 from ,width" FOR EVERY OUTPUT.

I already can extract the information for a single output, but I don’t know how to get it for each.

Has anyone got an idea how to solve that? I appreaciate any help very much!

Kind regards,  
Fabian

{  
“header”: {  
…  
},

```
"output 1": {
    "general data": {
        "attribute 1": 43.57116,
        "attribute 2": 43.57116,
        "attribute 3": 43.57116
    },
    "width": {
        "attribute 1": [
            0,
            1257.0,
            43.57116
        ],
        "attribute 2": [
            167,
            1257.0,
            43.57116
        ],
        "attribute 3": [
            333,
            1257.0,
            43.57116
        ]
    }  
},

"output 2": {
    "general data": {
        "attribute 1": 43.57116,
        "attribute 2": 43.57116,
        "attribute 3": 43.57116
    },
    "width": {
        "attribute 1": [
            0,
            1257.0,
            43.57116
        ],
        "attribute 2": [
            167,
            1257.0,
            43.57116
        ],
        "attribute 3": [
            333,
            1257.0,
            43.57116
        ]
    }
    
},
"output 3": {
    "general data": {
        "attribute 1": 43.57116,
        "attribute 2": 43.57116,
        "attribute 3": 43.57116
    },
    "width": {
        "attribute 1": [
            0,
            1257.0,
            43.57116
        ],
        "attribute 2": [
            167,
            1257.0,
            43.57116
        ],
        "attribute 3": [
            333,
            1257.0,
            43.57116
        ]
    }
    
}

```

}

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [November 3, 2022, 8:00pm UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/2 "2022-11-03T20:00:21Z")

</div>

Hi @fseck

Welcome to the KNIME community! You can also achieve this directly with a JSONPath and ungroup node.

For general data, attribute 1 → use path `*['general data']['attribute 1']`

_(Matches are automatically highlighted in blue)_

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/e/e/ee13164c514b3cd88060112638ecb4f2075b72ea.png)

For width,attribute 1, third value → use path `*['width']['attribute 1'][2]`

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/9/f/9fdc27ca5681a7656c185ccb46618b2c91fabb7b.png)

Make sure you have the List thickbox checked. If you then ungroup those two lists, you’ll get all individual values (which happens to be same for all of them in your example).

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/6/1/61792e6b7a3a3e3db941c6a7710b46b6e76b278d.png)

Hope this provides some inspritation!

---

<div class="post-metadata">

**Author:** ![fseck](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/f/47e85d/32.png) [@fseck](https://forum.knime.com/u/fseck)\
**Post date:** [November 3, 2022, 11:03pm UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/3 "2022-11-03T23:03:56Z")

</div>

Hey Arjen!

Thank you a lot, I really appreciate your help!!! I think for you it was super easy, but it was exactly what I’ve been looking for 🙂

But now I discovered a new problem:

For each repeating ,output" that I need to extract information from, there exists a condition that makes all attributes of that ,output" null:

“error”: {  
“attribute 1”: true  
},

If an attribute is ,null" I receive a question mark in my result table (which is ok for me). But somehow for the \*[‘width’][‘attribute 1’]**[2]** I don’t get a question mark, but the next found result (which does belong to the next output that has a value for that requested attribute). I hope that was formulated so you understand it.

For example: I have 10 outputs. Output #5,6,7 have null attributes bc of the true condition. Then the rows #8,9,10 (last three) don’t have a value for that attribute from \*[‘width’][‘attribute 1’][2] because it was assigned to #5,6,7 (even though their attribute is null).

Do you have any idea how I can solve that? A question mark would be sufficient for me.

Very kind regards,  
Fabian

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [November 3, 2022, 11:34pm UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/4 "2022-11-03T23:34:59Z")

</div>

Do you have another example json that includes such a scenario? Preferably one or two outputs from each type (normal one and the null attributes)

The path needs to be adjusted accordingly because it’s probably too generic right now but that’s a guessing game without seeing it I’m afraid. Most likely it needs to be done in multiple steps.

---

<div class="post-metadata">

**Author:** ![fseck](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/f/47e85d/32.png) [@fseck](https://forum.knime.com/u/fseck)\
**Post date:** [November 4, 2022, 8:47am UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/5 "2022-11-04T08:47:36Z")

</div>

“output 1”: {

```
    "error": {
        "attribute 1": true
    },
    "general data": {
        "attribute 1": null,
        "attribute 2": null,
        "attribute 3": null
    },
    "width": {
        "attribute 1": null,
        "attribute 2": null,
        "attribute 3": null
    },
},

"output 2": {
    "error": {
        "attribute 1": false
    },
    "general data": {
        "attribute 1": 19.942478,
        "attribute 2": 18.22136,
        "attribute 3": 23.00542
    },
    "width": {
        "attribute 1": [
            0,
            1174.0,
            18.22136
        ],
        "attribute 2": [
            167,
            1165.5,
            18.3929
        ],
        "attribute 3": [
            333,
            1164.0,
            18.75504
        ]
    }
},

"output 3": {
    "error": {
        "attribute 1": false
    },
    "general data": {
        "attribute 1": 17.942478,
        "attribute 2": 19.22136,
        "attribute 3": 22.00542
    },
    "width": {
        "attribute 1": [
            0,
            1175.0,
            16.22136
        ],
        "attribute 2": [
            168,
            1167.5,
            17.3929
        ],
        "attribute 3": [
            334,
            1165.0,
            17.75504
        ]
    }
}

```

It would look like this.

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [November 4, 2022, 9:10am UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/6 "2022-11-04T09:10:39Z")

</div>

@fseck Thanks! As expected, can be achieved with one additional path query.

Change the width attribute to `*['width']['attribute 1']` of **output type JSON**. That will pickup the entire array of values, including the null.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/d/2/d2bdd5897f44f8cf4bcea1277b99dedcf92d45f0.png)

Ungroup it again and then use another JSONPath node to get the third element again from the array (if it exists) with `$[2]`

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/5/7/577c15fd3d11b62f5566bf7fad1d22e4116b077c.png)

WF:  
[JSON Path extract same attributes for different objects.knwf](https://forum.knime.com/uploads/short-url/8Q0OkJI5TSBQqya2FOMJrZAjKv8.knwf) (22.3 KB)

---

<div class="post-metadata">

**Author:** ![fseck](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/f/47e85d/32.png) [@fseck](https://forum.knime.com/u/fseck)\
**Post date:** [November 4, 2022, 9:48am UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/7 "2022-11-04T09:48:36Z")

</div>

first of all thank you!!

actually I would like to extract not only the value \*[‘width’][‘attribute 1’][2] from attribute 1, but also from 2 and 3.  
Using the way you proposed, I would get several (in this case 3) json format results that I would need to use the Ungroup node on. But as far as I know, a Ungroup node only works for one json. So I would need to use 3 of them??? Or can you think of a better solution?

I am sorry for the amount of questions, but I have very few experience with json and Knime in general!

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [November 4, 2022, 9:57am UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/8 "2022-11-04T09:57:55Z")

</div>

> [@fseck](#):
>
> But as far as I know, a Ungroup node only works for one json. So I would need to use 3 of them???

You don’t. Just add as many queries as you like to the JSONpath. For example:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/b/b/bbf84c764247ab2b5bfd873ecc6fc84b873efb9f.png)

In the ungroup node, move all columns to the include section and select enforce exclusion. That way all new columns of type list are automatically included.

Example:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/3/4/34c777c711bdd88f4cada6c3b08f72cde7f15b35.png)

---

<div class="post-metadata">

**Author:** ![fseck](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/f/47e85d/32.png) [@fseck](https://forum.knime.com/u/fseck)\
**Post date:** [November 4, 2022, 10:08am UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/9 "2022-11-04T10:08:57Z")

</div>

I was talking about the second JSON Path node.

Then I get a warning that there are multiple JSON columns (because now we have 3 lists of 3 values each) and I have to select one as the input.

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [November 4, 2022, 10:24am UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/10 "2022-11-04T10:24:47Z")

</div>

I see. Then I would put a JSON Column Combiner in between and query that. This way is a lot more dynamic and easier to manage compared to putting multiple nodes in there that do the same kind of operation.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/8/5/8504dd41fb198bd03dce421cbf1c8c2619e8b6ab.png)

Output:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/f/5/f58ff3d260df7d56db01415c3e379790461ae3a6.png)

WF V2:  
[JSON Path extract same attributes for different objects v2.knwf](https://forum.knime.com/uploads/short-url/2obzAQc7VNN4seQnMkiDZchO1zI.knwf) (36.1 KB)

---

<div class="post-metadata">

**Author:** ![fseck](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/f/47e85d/32.png) [@fseck](https://forum.knime.com/u/fseck)\
**Post date:** [November 5, 2022, 4:51pm UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/11 "2022-11-05T16:51:15Z")

</div>

Hey Arjen!

that works perfectly for me 🙂 thank you, again.  
You really helped, I am glad this forum and people like you who help exist.

If some new questions pop up, I will get back to this topic.

Have a good weekend!

---

<div class="post-metadata">

**Author:** ![Daniel\_Weikert](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@Daniel\_Weikert](https://forum.knime.com/u/Daniel_Weikert)\
**Post date:** [November 7, 2022, 5:35pm UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/12 "2022-11-07T17:35:34Z")

</div>

Hi @ArjenEX  
could you quickly explain the difference between $. and \* (asterisk) for selecting json parts?  
thanks

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [November 14, 2022, 5:36pm UTC](https://forum.knime.com/t/json-path-extract-same-attributes-for-different-objects/48598/13 "2022-11-14T17:36:33Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
