0

Part of json object as below, need to extract questionId and check whether it is number:

{
    "rootProductQuestionId": "17",
    "questionAnswers": [ 
        {
            "question": "",
            "questionId": "17",
            "answer": ""
        }
    ],

    "productId": "8",
    "notes": ""
}
saw303
  • 8,051
  • 7
  • 50
  • 90
Abhram
  • 49
  • 1
  • 1
  • 6

1 Answers1

3

You have an option for isNumber() check, something like:

import groovy.json.jsonSlurper
def jsonSlurper = new JsonSlurper()
def json = jsonSlurper.parseText('{"rootProductQuestionId":"17","questionAnswers":[{"question":"","questionId":"17","answer":""}],"productId":"8","notes":""}')
return json.questionAnswers.questionId[0].isNumber()