Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse .json file with a gradle task and get the json data from it?

Is there a way where in I can parse a xyz.json file with help of a gradle task and get all the individual json data inside it? for eg. I want to parse this data which is stored in a xyz.json file in my assets folder and get all the values inside it, eg. get the value of "type".

{
  "type":"xyz",
  "properties": {
    "foo": {
      "type": "pqr"
    },
    "bar": {
      "type": "abc"
    },
    "baz": {
      "type": "lmo"
    }
  }
}
like image 552
Omkar Amberkar Avatar asked Jun 15 '16 01:06

Omkar Amberkar


1 Answers

You can create a gradle task like this

gradle myTask{
 doLast{
  def inputFile = new File("xyz.json")
  def json = new JsonSlurper().parseText(inputFile.text)
  def labels = json.properties.foo.type //This will return "pqr"
 }
}
like image 127
jitinsharma Avatar answered Oct 08 '22 01:10

jitinsharma