fork download
  1. def response = '''{
  2. "drafts" : [
  3. {
  4. "period" : "202101",
  5. "data" : {
  6. "name" : "Kalle Kula",
  7. "epost" : "kalle@kula.se"
  8. }
  9. },
  10. {
  11. "period" : "202102",
  12. "data" : {
  13. "name" : "Krille Krokodil",
  14. "phone" : "9876543210"
  15. }
  16. }
  17. ]
  18. }'''
  19. def expectedPeriods = ['202101', '202102']
  20. def expectedData = [202101:[name: 'Kalle Kula', epost: 'kalle@kula.se'], 202102: [name: 'Krille Krokodil', phone: '9876543210']]
  21. def json = new groovy.json.JsonSlurper().parseText(response)
  22. assert expectedPeriods == json.drafts.period
  23.  
  24.  
  25. expectedData.keySet().each { period ->
  26. println expectedData[period]
  27. println json.drafts.find{it.period == "$period"}.data
  28. assert expectedData[period] == json.drafts.find{it.period == "$period"}.data
  29. }
Success #stdin #stdout 1.77s 140560KB
stdin
Standard input is empty
stdout
[name:Kalle Kula, epost:kalle@kula.se]
[name:Kalle Kula, epost:kalle@kula.se]
[name:Krille Krokodil, phone:9876543210]
[name:Krille Krokodil, phone:9876543210]