0

This json file:

[ {
  "irc_server" : null,
  "ssh_keys" : [ ],
  "branches" : {
    "master" : {
      "running_builds" : [ ],
      "recent_builds" : [ {
        "outcome" : "no_tests",
        "status" : "no_tests",
        "build_num" : 1,
        "vcs_revision" : "748f8679cfc850582e3ada08210d8566a291328c",
        "pushed_at" : "2017-07-21T03:39:46.230Z",
        "added_at" : "2017-07-21T03:36:24.657Z"
      } ],
      "last_non_success" : {
        "outcome" : "no_tests",
        "status" : "no_tests",
        "build_num" : 1,
        "vcs_revision" : "748f8679cfc850582e3ada08210d8566a291328c",
        "pushed_at" : "2017-07-21T03:39:46.230Z",
        "added_at" : "2017-07-21T03:36:24.657Z"
      }
    }
  }]

How I parse it:

        projectsurl = get(API_PATH['PROJECTS'].format(self._token))  #get json data from url

        decodedjson = projectsurl.content.decode('utf-8') #decode to string

        jsondata = json.loads(decodedjson) #json obj

        return jsondata['vcs_revision']

How can i get a specific object from this array? Whenever I call return jsondata['vcs_revision'] It says i need an int not a string

0

1 Answer 1

1

You need to do jsondata[0]['vcs_revision'] because your jsondata is a list of dicts.

Sign up to request clarification or add additional context in comments.

2 Comments

That fixed the issue, should I delete this question or keep it?
Great. It's up to you what to do with the question. No one will care if you leave it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.