Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a POST does order of JSON variables matter?

Tags:

java

json

post

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.

like image 312
k9b Avatar asked Jan 10 '23 03:01

k9b


1 Answers

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.

like image 58
thegeko Avatar answered Jan 18 '23 15:01

thegeko