fork(5) download
  1. def jsonString = """{ "Errors": [],
  2. "Loans": [
  3. {
  4. "Applications": [
  5. {
  6. "id": 1,
  7. "name": "test"
  8. }
  9. ]
  10. },
  11. {
  12. "Applications": [
  13. {
  14. "id": 2,
  15. "name": "test3"
  16. },
  17. {
  18. "id": 3,
  19. "name": "test3"
  20. }
  21. ]
  22. }
  23. ]
  24. }"""
  25.  
  26. def json = new groovy.json.JsonSlurper().parseText(jsonString)
  27.  
  28. //To get all loan application by Id
  29. def getApplicationById = {id -> json.Loans.Applications.flatten().find{id == it.id}}
  30. println getApplicationById(3)
  31.  
Success #stdin #stdout 1.12s 2252800KB
stdin
Standard input is empty
stdout
[id:3, name:test3]