You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Marcel Sammut <su...@rogers.com> on 2009/12/01 01:35:24 UTC

T5 JSON Preserving Order

Greeting,
Is it possible to create JSON objects (JSONObject, JSONArray) where the
order of items in the list is preserved by the order they are entered?

Why does JSONOArray return a pair of key and name entries in a different
order then it was originally created?

For Example:
JSONObject response = new JSONObject();
response.put("success", true);
response.put("total", 50);
response.put("metaData", new JSONArray()...);
response.put("records", new JSONArray()...);
response.put("columns", new JSONArray()...);

The above returns a JSON formatted string:
{"total":50,"columns":[{...}],"records":[{...}],"success":true,"metaData":{...},{...},{...},{...}]}}

The order of the output is unpredictable.  Is there a way to have the
Tapestry JSON objects maintain the order of their lists (via LinkedHashMap
for example?)?

Thanks,
Marcel
-- 
View this message in context: http://old.nabble.com/T5-JSON-Preserving-Order-tp26584717p26584717.html
Sent from the Tapestry - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: T5 JSON Preserving Order

Posted by Howard Lewis Ship <hl...@gmail.com>.
Order of keys is not predictable and neither the client side nor the
server side should care (though I realize this can cause some hiccups
when testing!).

Order of items within a JSON array are in the order they are added.

On Mon, Nov 30, 2009 at 4:35 PM, Marcel Sammut <su...@rogers.com> wrote:
>
> Greeting,
> Is it possible to create JSON objects (JSONObject, JSONArray) where the
> order of items in the list is preserved by the order they are entered?
>
> Why does JSONOArray return a pair of key and name entries in a different
> order then it was originally created?
>
> For Example:
> JSONObject response = new JSONObject();
> response.put("success", true);
> response.put("total", 50);
> response.put("metaData", new JSONArray()...);
> response.put("records", new JSONArray()...);
> response.put("columns", new JSONArray()...);
>
> The above returns a JSON formatted string:
> {"total":50,"columns":[{...}],"records":[{...}],"success":true,"metaData":{...},{...},{...},{...}]}}
>
> The order of the output is unpredictable.  Is there a way to have the
> Tapestry JSON objects maintain the order of their lists (via LinkedHashMap
> for example?)?
>
> Thanks,
> Marcel
> --
> View this message in context: http://old.nabble.com/T5-JSON-Preserving-Order-tp26584717p26584717.html
> Sent from the Tapestry - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: T5 JSON Preserving Order

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 30 Nov 2009 22:35:24 -0200, Marcel Sammut <su...@rogers.com>  
escreveu:

> Greeting,

Hi!

> Is it possible to create JSON objects (JSONObject, JSONArray) where the
> order of items in the list is preserved by the order they are entered?

AFAIK, now, it is not.

> Why does JSONOArray return a pair of key and name entries in a different
> order then it was originally created?

Why would you need to keep the ordering of keys?

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org