fork(4) download
  1. /**
  2. * Ref:
  3. *
  4. **/
  5.  
  6. def json = """{
  7. "uri": "VehiclesandGadgets",
  8. "Types": {
  9. "Vehicle": [{
  10. "label": "Click to expand",
  11. "value": {
  12. "Cars": [{
  13. "label": "Click to expand",
  14. "value": {
  15. "Properties": [{
  16. "Make": "Honda",
  17. "Model": "Civic",
  18. "Color": "Red"
  19. }],
  20. "Specifications": [{
  21. "Engine": "V6",
  22. "Gear": "Auto",
  23. "Drive": "AWD"
  24. }]
  25. },
  26. "ov": true
  27. }]
  28. },
  29. "ov": true
  30. }],
  31. "Gadget": [{
  32. "label": "Click to expand",
  33. "value": {
  34. "Gaming": [{
  35. "label": "Click to expand",
  36. "value": {
  37. "Properties": [{
  38. "Type": "Xbox",
  39. "Model": "One",
  40. "Color": "Black"
  41. }]
  42. },
  43. "ov": true
  44. }]
  45. },
  46. "ov": true
  47. }]
  48. },
  49. "isFavorite": false
  50. }"""
  51.  
  52. def jsonRes = new groovy.json.JsonSlurper().parseText(json)
  53. def make = jsonRes.Types?.Vehicle?.value?.Cars?.value?.Properties?.Make
  54. def result = make ? make.flatten()[0] : 'NA'
  55. println result
  56.  
Success #stdin #stdout 1.44s 2911744KB
stdin
Standard input is empty
stdout
Honda