V
V
Valeriu1472017-05-08 14:16:06
linux
Valeriu147, 2017-05-08 14:16:06

How to get the necessary values ​​from a JSON file in unix?

Good afternoon. There is a dropbox account, it has a list of files with logs, I would like to get a list of the contents of the folder in the dropbox. I use the dropbox api and get the whole thing:

{"entries": [{".tag": "file", "name": "nginx.log.2017.05.07.gz", "path_lower": "/log_files/nginx.log.2017.05.07.gz", "path_display": "/log_files/nginx.log.2017.05.07.gz", "id": "id:ar6tGrcsTJAAAAAAAAMGEA", "client_modified": "2017-05-08T09:44:23Z", "server_modified": "2017-05-08T09:44:24Z", "rev": "337344a63f579", "size": 1707590, "content_hash": "b6de69589f769e0919726792ead6410950f0afbc9139b045ea4ad6655b10fd85"}, {".tag": "file", "name": "nginx.log.2017.05.09.gz", "path_lower": "/log_files/nginx.log.2017.05.09.gz", "path_display": "/log_files/nginx.log.2017.05.09.gz", "id": "id:ar6tGrcsTJAAAAAAAAMGEQ", "client_modified": "2017-05-08T09:44:25Z", "server_modified": "2017-05-08T09:44:25Z", "rev": "337354a63f579", "size": 1707590, "content_hash": "88981b3cb4620ca73ac8b7a238967c932e6c22fdbdd4f29144190a97e25d5df3"}, {".tag": "file", "name": "nginx.log.2017.05.10.gz", "path_lower": "/log_files/nginx.log.2017.05.10.gz", "path_display": "/log_files/nginx.log.2017.05.10.gz", "id": "id:ar6tGrcsTJAAAAAAAAMGEg", "client_modified": "2017-05-08T09:44:27Z", "server_modified": "2017-05-08T09:44:27Z", "rev": "337364a63f579", "size": 1707590, "content_hash": "dc776911a22ec4fb2770ba6bfc5aaaee0c280517efd85816196039bc14f29215"}, {".tag": "file", "name": "nginx.log.2017.05.11.gz", "path_lower": "/log_files/nginx.log.2017.05.11.gz", "path_display": "/log_files/nginx.log.2017.05.11.gz", "id": "id:ar6tGrcsTJAAAAAAAAMGEw", "client_modified": "2017-05-08T09:44:28Z", "server_modified": "2017-05-08T09:44:29Z", "rev": "337374a63f579", "size": 1707590, "content_hash": "9ed8c9e4434ce9fe11ec086a1e18de8ee44515fed76361ca4fe955a2bb2173ed"}, {".tag": "file", "name": "nginx.log.2017.05.12.gz", "path_lower": "/log_files/nginx.log.2017.05.12.gz", "path_display": "/log_files/nginx.log.2017.05.12.gz", "id": "id:ar6tGrcsTJAAAAAAAAMGFA", "client_modified": "2017-05-08T09:44:30Z", "server_modified": "2017-05-08T09:44:32Z", "rev": "337384a63f579", "size": 1707590, "content_hash": "04e090507ce3c1dca9b9659561056daaa4ca9eb13b4edb5f704496ae9fe2054d"}], "cursor": "AAGTiqg1Wqg2ZsS3R7P6rV-6TrFPYIu827rILrrtcGVW8z51P0UXSizxHKKdMx8k8gc8t3JB5eeoCWxPpC-bT_gv-4y22WbZGHIEDz74CFdzi_2kpn7lDbJ_HVVTdkHEtShtEiHZ4EQhrZJtCZ_8vk0yvmkMuRTsmxkD30q2VYHV54MqVRmytvZjqGTVt5NL41PPfbkBfFMWjIWq-MxOgVxm", "has_more": false}

How can I get just a list of files, without unnecessary technical information, as I see here, awk won't do much. It would be desirable to get it in a readable form
, like this : 2017.05.12.gz

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Swartalf, 2017-05-08
@Swartalf

Today I did similar things, so I'll simplify:
you_json_output | jq '.entries | .[] | .name'

D
devalone, 2017-05-08
@devalone

you can do something like this:

#!/usr/bin/env python3

import json

data = 'your_json_data_here'

j = json.loads(data)
for entry in j['entries']:
        print(entry['name'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question