0

I'm trying to parse a response from a ruTorrent request with jq in Linux. It looks like below. I've never seen json like that before, there aren't any keys for me to use in jq as a filter. How would you get a list of all the hashes? They seem to be the name of objects, but I can't list them.

Also, I wonder how would you filter to get the dates (in seconds, ex. 1622459402) in the objects? I'm used to everything having keys, and thats how know how to do it.

UPDATE: The below article does NOT answer my question. My json does not contain any keys except "t" and "cid", they are not what I am after.

How to get key names from JSON using jq

    {
      "t": {
        "2C3D7D91DFD0A57CFCA8B7092347B311088D3B6E": [
          "1",
          "0",
          "1",
          "1",
          "Young.Sheldon.S04.1080p.x265-ZMNT",
          "4764367221",
          "1136",
          "1136",
          "4764367221",
          "5201425130",
          "1091",
          "0",
          "0",
          "4194304",
          "",
          "0",
          "0",
          "0",
          "0",
          "0",
          "2",
          "1622459402",
          "0",
          "0",
          "1136",
          "/home/xxxxxxxx/files/Young.Sheldon.S04.1080p.x265-ZMNT",
          "1622421479",
          "2",
          "1",
          "",
          "",
          "4436465131520",
          "1",
          "1"
        ],
        "FAC73275BC376C4C26DFDA41D991D021838DB778": [
          "1",
          "0",
          "1",
          "1",
          "Joshy.2016.NORDIC.1080p.BluRay.REMUX.AVC.DTS-HD.MA.5.1-Danishbits",
          "21160180253",
          "5045",
          "5045",
          "21160180253",
          "4470554624",
          "211",
          "114688",
          "0",
          "4194304",
          "",
          "1",
          "0",
          "1",
          "0",
          "0",
          "2",
          "1622459402",
          "0",
          "0",
          "5045",
          "/home/xxxxxxxx/files/Joshy.2016.NORDIC.1080p.BluRay.REMUX.AVC.DTS-HD.MA.5.1-Danishbits",
          "1622413504",
          "2",
          "1",
          "",
          "",
          "4436465131520",
          "1",
          "1"
        ],
        "671CA27A76DC35E8E9F46723F1F6596A8BC75DA0": [
          "1",
          "0",
          "1",
          "1",
          "Working.Girl.1988.1080p.Bluray.REMUX.AVC.DTS-HD.MA.5.1-4K4U",
          "29680778067",
          "14153",
          "14153",
          "29680778067",
          "12426936320",
          "418",
          "0",
          "0",
          "2097152",
          "",
          "1",
          "0",
          "1",
          "0",
          "0",
          "2",
          "1622459402",
          "0",
          "0",
          "14153",
          "/home/xxxxxxxx/files/Working.Girl.1988.1080p.Bluray.REMUX.AVC.DTS-HD.MA.5.1-4K4U",
          "1622440882",
          "2",
          "1",
          "",
          "",
          "4436465131520",
          "1",
          "1"
        ]
  },
  "cid": 1423760010
}
Error2k
  • 21
  • 3
  • You got an array of values. Can you query for a more well formed JSON? Which is the URL you are calling? – Antonio Petricca May 31 '21 at 13:48
  • I've not been able to find the data anywhere else. I don't have ssh access to the rtorrent server. The URL is private, but it looks like this: https://xxxxxxx.seedbox.io/rutorrent/plugins/httprpc/action.php – Error2k May 31 '21 at 13:57
  • This is how I got the dates out of that json: jq '.t| .[] | .[-8]' . Here's an example of getting the title and the date on the same line jq -r '.t| .[]| "\(.[4]), \(.[-8])"' – Mark May 31 '21 at 16:26
  • This is not an issue with parsing the JSON; this is an issue generating the JSON. As such, you need to take it up with the source system. No tool can make up meaningful key names given the output you've posted. – Joe Casadonte May 31 '21 at 16:27
  • Here's your likely list of fields: https://github.com/Novik/ruTorrent/blob/master/plugins/httprpc/action.php#L91 – Joe Casadonte May 31 '21 at 16:31
  • `jq -r '.t | keys[]'` and `jq -r '.t[][21]'`. Isn't that what you're after? – Reino May 31 '21 at 17:01
  • Thank you! This was exactly what I was looking for. You were all very helpfull! Very much appreciated! – Error2k May 31 '21 at 18:07
  • The keys of arrays are called indexes, and they are `0`, `1`, `2`, etc. In this case, you want `.[21]` – ikegami May 31 '21 at 21:48
  • 1
    @oguz ismail, Be careful when closing, especially when you do so single-handedly. The OP asked how to address array elements, not how to convert arrays into objects. Voting to reopen. – ikegami May 31 '21 at 21:49
  • @ikegami OP says *How would you get a list of all the hashes? They seem to be the name of objects, but I can't list them.* and the duplicate target answers that question. Though if you want to post a better answer I will vote to reopen too. – oguz ismail Jun 01 '21 at 04:21
  • @oguz ismail, Like I said, be more careful. Reading one sentence and thinking you know what the question is about is not right. Again, the linked Q&A doesn't answer this question. But, there does seem to be two different questions in here. So I guess it should remained closed ("too broad") until one is removed. – ikegami Jun 01 '21 at 06:06
  • So @Error2k, do you have two questions or one? If you have two, ask them separately. Either way, please edit your question to be clearer, starting by providing the desired output. – ikegami Jun 01 '21 at 06:12

0 Answers0