6

Im writing a program to upload my companies orders to an order review site through a POST request. It takes a JSON Object, and it starts like this

{
 "utoken": "XVUYvqaRLPtjfuj1OyNbyqw1cv0R0f76g4PadwmR",
 "platform": "general",

However when I create my JSONObject using JSON.simple

JSONObject test = new JSONObject();
test.put("utoken", "awooga");
test.put("platform", "general");

It puts it into alphabetical order when I print it out

{
  "platform": "general",
  "utoken": "awooga"

Does this matter? I dont think it should, but just want to make certain as I've never ran into this before.

k9b
  • 1,457
  • 4
  • 24
  • 54

2 Answers2

12

As per JSON standard, official definition of object states:

An object is an unordered set of name/value pairs.

Therefore the order does not matter. Obviously from the perspective of the server receiving the POST request, the order can be parsed from HTTP header and reacted upon. I suppose however this is not of your interest, as it does not make much sense to do so.

thegeko
  • 1,382
  • 1
  • 13
  • 18
-1

See an answer here

TL;DR - order isn't promised to stay the same

Community
  • 1
  • 1
Tom Teman
  • 1,975
  • 3
  • 28
  • 43