How to prevent ordering of json string during parsing using groovy jsonslurper? -


i have josn string below,

def input = '''{"name":"abul","age":30,"street":"uttara"}''' 

after parsing json string input below,

def output = new groovy.json.jsonslurper().parsetext(input) 

i got following value of output

'''{"age":30,"name":"abul","street":"uttara"}''' 

but expect no change in order i.e, expected result

  {"name":"abul","age":30,"street":"uttara"}  

how can using same lib i.e, groovy.json.jsonslurper

you can't.

if want ordering, you'll have use json array.

an object unordered collection of 0 or more name/value pairs, name string , value string, number, boolean, null, object, or array.

an array ordered sequence of 0 or more values.

reference : http://www.rfc-editor.org/rfc/rfc7159.txt


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -