1

I have a JSON string as below which I am obtaining from a web service call. How can I retrieve the array from the builds key.

 {
  "actions" : [
    {

    },
    null,
    {

    }
  ],
  "description" : "<a href=\"ws/product/target/product-10.7-SNAPSHOT.zip\" style=\"font-size: 50px\">Download Branch Build</a>",
  "displayName" : "EPIC-AUTODEV-8413",
  "displayNameOrNull" : null,
  "name" : "EPIC-AUTODEV-8413",
  "url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/",
  "buildable" : false,
  "builds" : [
    {
      "number" : 71,
      "url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/71/"
    },
    {
      "number" : 70,
      "url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/70/"
    },
    {
      "number" : 69,
      "url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/69/"
    },
    {
      "number" : 68,
      "url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/68/"
    },
    {
      "number" : 67,
      "url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/67/"
    },
    {
      "number" : 66,
      "url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/66/"
    },

}

I tried with tree=builds[*], but it gives me output like this

{"builds":[{},{},{},{},{},{},{},{},{},{},{}]}
booyaa
  • 4,437
  • 2
  • 26
  • 32
Srikant Barik
  • 133
  • 2
  • 12

1 Answers1

0

try out javascript method JSON.parse, below is example

var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');

the above will give you object and than you refer part you want.

and if you want your object convert back in to json than try JSON.stringify()

var myJSON = JSON.stringify(obj);
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263