Bernardo

 

Thanks for this. After sending my previous mail, I did what I should have done 
first and looked at list of collection objects in the system browser. So I 
discovered OrderedDictionary for the first time. I am pleased to see that this 
is the key to the solution.

 

Peter

 

From: Pharo-users [mailto:pharo-users-boun...@lists.pharo.org] On Behalf Of 
Bernardo Ezequiel Contreras
Sent: 30 June 2016 16:17
To: Any question about pharo is welcome <pharo-users@lists.pharo.org>
Subject: Re: [Pharo-users] Provide a mapping for a collection of <Association>s 
in NeoJSON

 

Peter,

  i had the same issue, i couldn't find the way to do it, but i hack my own 
writing like this

 

NDBFood>>neoJsonOn: neoJSONWriter

            "custom writing"

 

            neoJSONWriter

                        writeMap:

                                    (OrderedDictionary new

                                                add: 'ndb_no' -> ndbno;

                                                add: 'full_name' -> name;

                                                add: 'food_group' -> fg;

                                                add: 'factors' -> self factors;

                                                add: 'nutrients' -> self 
nutrients;

                                                yourself)

 

i just implement my own writing for my objects.

 

HTH

 

On Thu, Jun 30, 2016 at 12:06 PM, PBKResearch <pe...@pbkresearch.co.uk 
<mailto:pe...@pbkresearch.co.uk> > wrote:

Hello

 

I have recently used NeoJSON for the first time. All went pretty well, but I 
would like to make a small tweak to the output, which probably involves 
defining a mapping. I have read through the information in the NeoJSON pdf, and 
also looked at the class comments, but I am  a bit lost. Could Sven or anyone 
please give me a hint?

 

What I want is to construct a JSON object as a Pharo dictionary, but then 
control the order in which the fields are output to the JSON file. Clearly the 
order is irrelevant for a computer, but it could be helpful to a human reader 
to put them in an order which reflects the way humans think about the objects. 
The keys of a dictionary are of course unordered, so this is not possible, but 
if we step back a bit we see that a dictionary is often constructed from a 
collection of associations; if we could stop at this stage, and have a mapping 
which outputs the associations in the order in which they appear in the 
collection, this would give the control I am looking for.

 

Am I talking nonsense, or is there any way of implementing this using NeoJSON 
mappings?

 

Best wishes

 

Peter Kenny





 

-- 

Bernardo E.C.

 

Sent from a cheap desktop computer in South America.

Reply via email to