Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Unknown how to get the JSON path for an unnamed json array?

Asked by
uhTeddy 101
6 years ago
Edited 6 years ago

right now I have this JSON.

{
 "kind": "youtube#channelListResponse",
 "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/SGu14Buo6xWrEuoFga6kBy4vZBs\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/Gtb_6T1CwMLCWtseKBhUt_R95fg\"",
   "id": "UC-lHJZR3Gqxm24_Vd_AJ5Yw",
   "statistics": {
    "viewCount": "19368312391",
    "commentCount": "0",
    "subscriberCount": "73782288",
    "hiddenSubscriberCount": false,
    "videoCount": "3672"
   }
  }
 ]
}

on line 9 you see an unnamed array but I have no Idea how to get the path for that.

I used this website to get what I used below: http://jsonpathfinder.com/

While I tried many paths to get the subscriberCount. The one below is one of the ones I used and cannot figure out how to get the value of it.

info.items[0].statistics.subscriberCount
0
If you need any more information feel free to comment! uhTeddy 101 — 6y
0
Arrays start at 1, not 0 hiimgoodpack 2009 — 6y

1 answer

Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
6 years ago
Edited 6 years ago

JavaScript array indices start at 0, therefore this website -- thinking you were trying to access the element in JavaScript -- gave you a zero-based array index.

However Lua array indices start at 1, so the index is wrong.

Use array index 1 and everything should work fine.

Ad

Answer this question