0

Using the v2 of the box api, I use the folder items request to get information on files in a folder: http://developers.box.com/docs/#folders-retrieve-a-folders-items

I'm looking at trying to parse the response data. Any ideas how I can do this in bash to easily find a file in the user's account? I would like to find the name of the file where I can get the ID of the file as well.

response looks something like this:

{
    "total_count": 25,
    "entries": [
        {
            "type": "file",
            "id": "531117507",
            "sequence_id": "0",
            "etag": "53a93ebcbbe5686415835a1e4f4fff5efea039dc",
            "name": "agile-web-development-with-rails_b10_0.pdf"
        },
        {
            "type": "file",
            "id": "1625774972",
            "sequence_id": "0",
            "etag": "32dd8433249b1a59019c465f61aa017f35ec9654",
            "name": "Continuous Delivery.pdf"
        },
        { ...
Peter
  • 2,551
  • 1
  • 14
  • 20
ikwyl6
  • 851
  • 1
  • 7
  • 12
  • That response is in [JSON](http://en.wikipedia.org/wiki/JSON); you should use a programming language and library with JSON support, rather than raw Bash. (Alternatively, you can ask the Box API to give you a response in XML instead; in that case, you would use a programming language and library with XML support, rather than raw Bash.) – ruakh Sep 05 '12 at 20:43

2 Answers2

0

For bash, you can use sed or awk. Look at Parsing JSON with Unix tools.

Also if you can use a programming language, then python can be your fastest option. it has a nice module json http://docs.python.org/library/json.html. It has a simple decode API which will give a dict as the output

Then

import json
response_dict = json.loads(your_response)
Community
  • 1
  • 1
auny
  • 1,920
  • 4
  • 20
  • 37
  • This is a good answer but I think adding the ".xml" to the request is probably the easiest thing to do at this point. Thanks. – ikwyl6 Oct 03 '12 at 01:23
0

I recommend using jq for parsing/munging json in bash. It is WAY better than trying to use sed or awk to parse it.