fork(1) download
  1. import groovy.json.JsonSlurper
  2. import groovy.json.JsonOutput
  3. class Example {
  4.  
  5. static void main(String[] args) {
  6. def jsonSlurper = new JsonSlurper()
  7. def obj = jsonSlurper.parseText '''{"-1": {"description": "test1"},"222": {"description": "test2"},"223": {"description": "test3"},"224": {"description": "test4"},"recordsCount": 4}'''
  8. //println(obj.keySet()); //[-1, 222, 223, 224, recordsCount]
  9. Set<String> keySet=obj.keySet();
  10. List<String> keys = [];
  11. for(String key:keySet){
  12. if(key.isNumber())
  13. keys.add(key);
  14. }
  15. //println(keys); //[-1, 222, 223, 224]
  16. def output = JsonOutput.toJson(keys);
  17. //println(output); //["-1","222","223","224"]
  18. println output.toString()
  19. }
  20. }
Success #stdin #stdout 2.02s 135128KB
stdin
Standard input is empty
stdout
["-1","222","223","224"]