# Problem with my JQ

**URL:** <https://community.glideapps.com/t/problem-with-my-jq/58326>\
**Category:** Ask for Help\
**Created:** [February 22, 2023, 11:40pm UTC](https://community.glideapps.com/t/problem-with-my-jq/58326 "2023-02-22T23:40:56Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![marshru](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@marshru](https://community.glideapps.com/u/marshru)\
**Post date:** [February 22, 2023, 11:40pm UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/1 "2023-02-22T23:40:56Z")

</div>

Continuing the discussion from [Transform JSON with JQ](https://community.glideapps.com/t/transform-json-with-jq/56088/14):

I tried this same approach but it returns nothing. I ran the JQ in an online parser to make sure it worked first but it isn’t working the same in Glide. The Json is very short and properly formatted but I’m getting weird errors (seems to me it’s not making an assignment to “j”?):

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/3/73cb133a930da833796656b9eeaaa05e06261da2.png)

P2 is a Number column from 0 to 9.  
P1 is a lookup from another table containing the JSON:  
{  
“page”:1,  
“results”:[  
{  
“adult”:false,  
“backdrop\_path”:“/wvdiTDDBxI0lix4Wbc2qePfgkA2.jpg”,  
“genre\_ids”:[  
35,  
80,  
9648  
],  
“id”:107113,  
“origin\_country”:[  
“US”  
],  
“original\_language”:“en”,  
“original\_name”:“Only Murders in the Building”,  
“overview”:“Three strangers who share an obsession with true crime suddenly find themselves wrapped up in one.”,  
“popularity”:41.885,  
“poster\_path”:“/ArsVbYhS6DiFJtRAlV8ytAauNlp.jpg”,  
“first\_air\_date”:“2021-08-31”,  
“name”:“Only Murders in the Building”,  
“vote\_average”:8.5,  
“vote\_count”:935  
},  
{  
“adult”:false,  
“backdrop\_path”:“/m6C5RVGEHL8U08WIcgFh0xqUtON.jpg”,  
“genre\_ids”:[  
10767  
],  
“id”:210426,  
“origin\_country”:[  
“US”  
],  
“original\_language”:“en”,  
“original\_name”:“One Killer Question”,  
“overview”:“The Only Murders in the Building aftershow that isn’t afraid to tackle the hard question. One question. That’s it. Featuring host Ali Stroker, the show’s actors, a slew of celebrity superfans and one big murder to solve it just might be the only Only Murders In the Building aftershow you need to watch.”,  
“popularity”:1.585,  
“poster\_path”:null,  
“first\_air\_date”:“2022-06-28”,  
“name”:“One Killer Question”,  
“vote\_average”:2,  
“vote\_count”:1  
}  
],  
“total\_pages”:1,  
“total\_results”:2  
}

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/8/7/87e33e099e52c32cdaa5d544fa4175c01be3282a.png)

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [February 22, 2023, 11:44pm UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/2 "2023-02-22T23:44:46Z")

</div>

you need to fix your JSON to an array []

---

<div class="post-metadata">

**Author:** ![marshru](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@marshru](https://community.glideapps.com/u/marshru)\
**Post date:** [February 23, 2023, 12:30am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/3 "2023-02-23T00:30:47Z")

</div>

Ok, thanks, tried that, but still getting errors. I presume I have to index into the array now that I’ve done that, so changed the code slightly, and now get this:

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/4/f/4f0d5e5a04b95e5b742c5129cd87dc3dc15d473f.png)

(Note: I had a senior moment and hadn’t referenced the Index field before (not that this was the issue). I fixed that before trying again - per image above. )

If I don’t do that first index (say “JSON.parse” takes care of that), I get another error:

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/e/6e6894dcef6e7aaddb486cac08ad765a6b7486f4.png)

Which tells me I might be making progress but why didn’t it fail out of the if statement after the second Index rather than throw an error?

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/e/6e6894dcef6e7aaddb486cac08ad765a6b7486f4.png)

Sorry, I’m very new to JQuery and Javascript.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [February 23, 2023, 12:34am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/4 "2023-02-23T00:34:24Z")

</div>

Your payload is just the headers, so you need to address them by their name, not by positions…  
`return j.page`  
it should give you “1”

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [February 23, 2023, 12:38am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/5 "2023-02-23T00:38:00Z")

</div>

give me the fetch url, and what you wanna get from payload, and I will fix the code for you

---

<div class="post-metadata">

**Author:** ![marshru](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@marshru](https://community.glideapps.com/u/marshru)\
**Post date:** [February 23, 2023, 3:06am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/6 "2023-02-23T03:06:26Z")

</div>

Ok I kind of see, but this doesn’t work either:

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/d/ed304802e12927a09237ae45f6d310958bbaf08a.png)

---

<div class="post-metadata">

**Author:** ![marshru](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@marshru](https://community.glideapps.com/u/marshru)\
**Post date:** [February 23, 2023, 3:15am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/7 "2023-02-23T03:15:36Z")

</div>

Um, the URL has my API key so can’t send here but, basically, see below. As far as what I wanted to get - I was just experimenting, and to start with just want to get the two hits in a separate row.

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/c/5c5d4831cd1b26335537e0ede9b1052393a29179.png)

So I can enter any series name and get back all the hits from their site. The example result is for “only murders in the building” : the result comes back as show in the original message which I subsequently wrapped in an array format […] per discussion. See below for the actual JSON string returned:

{  
“page”:1,  
“results”:[  
{  
“adult”:false,  
“backdrop\_path”:“/wvdiTDDBxI0lix4Wbc2qePfgkA2.jpg”,  
“genre\_ids”:[  
35,  
80,  
9648  
],  
“id”:107113,  
“origin\_country”:[  
“US”  
],  
“original\_language”:“en”,  
“original\_name”:“Only Murders in the Building”,  
“overview”:“Three strangers who share an obsession with true crime suddenly find themselves wrapped up in one.”,  
“popularity”:41.885,  
“poster\_path”:“/ArsVbYhS6DiFJtRAlV8ytAauNlp.jpg”,  
“first\_air\_date”:“2021-08-31”,  
“name”:“Only Murders in the Building”,  
“vote\_average”:8.5,  
“vote\_count”:935  
},  
{  
“adult”:false,  
“backdrop\_path”:“/m6C5RVGEHL8U08WIcgFh0xqUtON.jpg”,  
“genre\_ids”:[  
10767  
],  
“id”:210426,  
“origin\_country”:[  
“US”  
],  
“original\_language”:“en”,  
“original\_name”:“One Killer Question”,  
“overview”:“The Only Murders in the Building aftershow that isn’t afraid to tackle the hard question. One question. That’s it. Featuring host Ali Stroker, the show’s actors, a slew of celebrity superfans and one big murder to solve it just might be the only Only Murders In the Building aftershow you need to watch.”,  
“popularity”:1.585,  
“poster\_path”:null,  
“first\_air\_date”:“2022-06-28”,  
“name”:“One Killer Question”,  
“vote\_average”:2,  
“vote\_count”:1  
}  
],  
“total\_pages”:1,  
“total\_results”:2  
}

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [February 23, 2023, 3:16am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/8 "2023-02-23T03:16:24Z")

</div>

You are trying to address an array that does not exist.  
The following works:

```auto
let json = JSON.parse(p1);
return JSON.stringify(json.results);

```

 ![CleanShot 2023-02-23 at 11.14.54@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/a/9a91723b62f95f290845e2cd2015e60a79fd43c2.png)

What are you actually trying to extract from that JSON?

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [February 23, 2023, 3:18am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/9 "2023-02-23T03:18:16Z")

</div>

Right…just extract the name of each show for example?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/d/9d5560fad0062a117f0a9607c18407a1d243ba92.jpeg)

---

<div class="post-metadata">

**Author:** ![marshru](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@marshru](https://community.glideapps.com/u/marshru)\
**Post date:** [February 23, 2023, 3:35am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/10 "2023-02-23T03:35:21Z")

</div>

Ok - I think I am misunderstanding the way the thing is called. What is in P1? I have a column with the JSON results in P1 and P2 is the index. Is that correct? Also, should this be an array or a string?

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [February 23, 2023, 3:49am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/11 "2023-02-23T03:49:29Z")

</div>

The JSON is passed into the JavaScript column as a string, and then the `JSON.parse()` method is used to convert that string to a JSON object.

You then directly access various attributes of the object.  
The index is useful if your JSON contains a collection (array) and you want to retrieve a specific element of the array.

Again, which specific items do you want to extract from your sample JSON?

If you share that, I’ll show you how to do it.

---

<div class="post-metadata">

**Author:** ![marshru](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@marshru](https://community.glideapps.com/u/marshru)\
**Post date:** [February 23, 2023, 4:03am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/12 "2023-02-23T04:03:15Z")

</div>

Yep, Ok this is what I thought. In the above I am trying to get each of the two “results” objects ( “results”:[{…},{…}]) - each in a new row. Happy to get anything from there at this stage, say "name’ or “overview” if that is easier. I just need to see some syntax that works. Nothing I’ve tried so far has had a result. I’ve attempted all the above suggestions with variations. I’m sure there’s something really obvious I’m getting wrong but can’t figure it out.

By the way - it looks like this hard coded in JQuery:

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/7/97049ad3a8ad02e1ed55881d818a1447773de683.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/4/64cc34f20502a5fff735f404f3be027942df384c.jpeg)

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [February 23, 2023, 4:09am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/13 "2023-02-23T04:09:59Z")

</div>

Okay, given the following JSON string:

```auto
 {
   "page":1,
   "results":[
      {
         "adult":false,
         "backdrop_path":"/wvdiTDDBxI0lix4Wbc2qePfgkA2.jpg",
         "genre_ids":[
            35,
            80,
            9648
         ],
         "id":107113,
         "origin_country":[
            "US"
         ],
         "original_language":"en",
         "original_name":"Only Murders in the Building",
         "overview":"Three strangers who share an obsession with true crime suddenly find themselves wrapped up in one.",
         "popularity":41.885,
         "poster_path":"/ArsVbYhS6DiFJtRAlV8ytAauNlp.jpg",
         "first_air_date":"2021-08-31",
         "name":"Only Murders in the Building",
         "vote_average":8.5,
         "vote_count":935
      },
      {
         "adult":false,
         "backdrop_path":"/m6C5RVGEHL8U08WIcgFh0xqUtON.jpg",
         "genre_ids":[
            10767
         ],
         "id":210426,
         "origin_country":[
            "US"
         ],
         "original_language":"en",
         "original_name":"One Killer Question",
         "overview":"The Only Murders in the Building aftershow that isn't afraid to tackle the hard question. One question. That's it. Featuring host Ali Stroker, the show's actors, a slew of celebrity superfans and one big murder to solve it just might be the only Only Murders In the Building aftershow you need to watch.",
         "popularity":1.585,
         "poster_path":null,
         "first_air_date":"2022-06-28",
         "name":"One Killer Question",
         "vote_average":2,
         "vote_count":1
      }
   ],
   "total_pages":1,
   "total_results":2
}

```

To extract the movie names, each on a separate row, use the following:

```auto
let json = JSON.parse(p1);
return json.results[p2].original_name;

```

 ![CleanShot 2023-02-23 at 12.08.01@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/8/38efa124680b4e660fc156d0e192aa787fab0568.png)

PS. (Which is basically the same as the example that Bob gave you earlier)

---

<div class="post-metadata">

**Author:** ![marshru](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@marshru](https://community.glideapps.com/u/marshru)\
**Post date:** [February 23, 2023, 4:29am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/14 "2023-02-23T04:29:08Z")

</div>

Yep - all the advice was correct 😳 I was not using the right syntax to stringify the whole object when trying that. It now works. Very pleased I’m half way round the world and not likely to bump into any of you. Many thanks all for your patience, and sorry to give you such a run around.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [February 23, 2023, 4:30am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/15 "2023-02-23T04:30:31Z")

</div>

No problems. We’re here to share and help. We’ve all been where you are at one point.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [February 23, 2023, 5:06am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/16 "2023-02-23T05:06:10Z")

</div>

Sorry, I had a customer meeting… but I see Darren and Robert took care of you 😉

---

<div class="post-metadata">

**Author:** ![Yohannan](https://avatars.discourse-cdn.com/v4/letter/y/96bed5/32.png) [@Yohannan](https://community.glideapps.com/u/Yohannan)\
**Post date:** [April 14, 2023, 5:21am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/17 "2023-04-14T05:21:29Z")

</div>

@Darren_Murphy  
I’m new too & i’m stuck with array data  
I am trying to take present data of every dates & want to seperate them by dates

I actually want to show attendance report of present & absent with names in collection of different dates

> **This is my JSON of 1 subject**
>
> {  
> “subjects”: [  
> {  
> “subject\_name”: “JJ12345”,  
> “attendance”: [  
> {  
> “date”: “2023-04-11T18:30:00.000Z”,  
> “attendance\_data”: {  
> “present”: [  
> “ID001”,  
> “ID003”  
> ],  
> “absent”: [  
> “ID002”  
> ]  
> }  
> },  
> {  
> “date”: “2023-04-12T18:30:00.000Z”,  
> “attendance\_data”: {  
> “present”: [  
> “ID001”,  
> “ID002”,  
> “ID003”  
> ],  
> “absent”: [  
> “”  
> ]  
> }  
> },  
> {  
> “date”: “2023-04-13T18:30:00.000Z”,  
> “attendance\_data”: {  
> “present”: [  
> “ID001”,  
> “ID002”,  
> “ID003”  
> ],  
> “absent”: [  
> “”  
> ]  
> }  
> }  
> ]  
> }  
> ]  
> }

 ![Screenshot 2023-04-14 104205](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/b/5bf92a43d74b30c1153b7e53342d156582153524.png)

 ![Screenshot 2023-04-14 105025](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/a/caacd24ff895c07121986bebeacf0b43fd359359.png)

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [April 14, 2023, 5:52am UTC](https://community.glideapps.com/t/problem-with-my-jq/58326/18 "2023-04-14T05:52:24Z")

</div>

Given your JSON structure:

- Create a working table and number the rows starting at zero
- Add a column that contains the JSON that you want to process
- Use JavaScript to extract the values that you need
- In each of the examples below, `p1` is your JSON string, and `p2` is the Row Index.

To extract the Subject Name:

```auto
let json = JSON.parse(p1);
return json.subjects[0].subject_name;

```

To extract the Date:

```auto
let json = JSON.parse(p1);
return json.subjects[0].attendance[p2].date;

```

To extract a list of those Present:

```auto
let json = JSON.parse(p1);
let present = json.subjects[0].attendance[p2].attendance_data.present;
return present.join(",");

```

To extract a list of those Absent:

```auto
let json = JSON.parse(p1);
let absent = json.subjects[0].attendance[p2].attendance_data.absent;
return absent.join(",");

```

End result:

 ![CleanShot 2023-04-14 at 13.48.39@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/f/2/f2616378c7433b022bbb1b899046e6750607b08c.png)

You may need to tweak the above if your JSON contains data for multiple Subjects, but this should be enough to get you started.
