What's missing is a "map" syntax. :)

#{
  'track' -> 'pharo'.
  'language' -> 'smalltalk'.
  'exercises' -> #{
     'slug' -> 'hello'.
     'id' -> 55.
     'topics' -> #('a' 'b' 'c') }
}

The #{ } would be a mix of the existing { } construct, but somehow
enforcing that elements return "association like" (#key and #value)
and sends #asDictionary to the resulting collection.

I cannot think of anything shorter than that except for what I use and
was already suggested:

ex := {
  #track->#pharo.
  #language->#smalltalk.
  #exercises->{
    #slug->'hello'.
    #id->55.
    #topics->#('a' 'b' 'c') } asDictionary } asDictionary.


Regards,

Esteban A. Maringolo

El vie., 1 mar. 2019 a las 9:08, Sven Van Caekenberghe
(<s...@stfx.eu>) escribió:
>
>
>
> > On 1 Mar 2019, at 12:32, Tim Mackinnon <tim@testit.works> wrote:
> >
> >
> >
> >> On 1 Mar 2019, at 10:35, Sven Van Caekenberghe <s...@stfx.eu> wrote:
> >>
> >> Forget about the way you are trying to implement it, to what would
> >>
> >>  { #key->#value. 1. true }
> >>
> >> be rendered in JSON ?
> >>
> >>  { "key":"value", 1, true }
> >>
> >> or
> >>
> >>  [ "key":"value", 1, true ]
> >>
> >> Both are illegal JSON.
> >
> >
> > You didn’t read what I said - with those 2 tiny changes - both of those 
> > given an exception just like STONJSON - the only difference is that I don’t 
> > have to put asDictionary everywhere.
> >
> > Anyway - I think I’ve learned a lot from this discussion - and as Pharo is 
> > malleable I can do my little nasty subclass until I get burned and then I 
> > will probably adopt a proper Config object like Henrik mentioned ;)
>
> Yes you can !
>
> > Just as a small additional question - when you do :
> >
> > ex := {
> >  #track->#pharo.
> >  #language->#smalltalk.
> >  #exercises->{
> >    #slug->'hello'.
> >    #id->55.
> >    #topics->#('a' 'b' 'c') } asDictionary } asDictionary.
> >
> > Am I right in thinking that with asDictionary the order won’t be 
> > deterministic (which is valid for JSON dictionaries, but annoying for 
> > diffing config files). This is why I was doing asOrderedDictionary as I 
> > though I had seen it change on me a few times when I was generating output.
>
> Right, #asDictionary or #asOrderedDictionary both work, it is up to you.
>
> But, like you said, there is no order in JSON, although it can help in 
> diffing.
>
> > Tim
>
>

Reply via email to