Re: [Pharo-users] How to write out simple Json?

2019-03-02 Thread Sven Van Caekenberghe
Come on, no it does not. It generates invalid JSON (as it should, but doing so silently is wrong). Json render: { 'track' -> 'pharo'. 'language' -> 'smalltalk'. 'exercises' -> { 'slug' -> 'hello'. 'id' -> 55. 'topics' -> #('a' 'b' 'c') } }. => '["track": "pharo","language":

Re: [Pharo-users] How to write out simple Json?

2019-03-01 Thread Paul DeBruicker
Of you load the JSON package from Squeaksource (http://www.squeaksource.com/JSON.html) You can do a JSON render: { 'track' -> 'pharo'. 'language' -> 'smalltalk'. 'exercises' -> { 'slug' -> 'hello'. 'id' -> 55. 'topics' -> #('a' 'b' 'c') } } and get a Json string or add

Re: [Pharo-users] How to write out simple Json?

2019-03-01 Thread Esteban Maringolo
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

Re: [Pharo-users] How to write out simple Json?

2019-03-01 Thread Sven Van Caekenberghe
> On 1 Mar 2019, at 12:32, Tim Mackinnon wrote: > > > >> On 1 Mar 2019, at 10:35, Sven Van Caekenberghe 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 } >> >>

Re: [Pharo-users] How to write out simple Json?

2019-03-01 Thread Tim Mackinnon
> On 1 Mar 2019, at 10:35, Sven Van Caekenberghe 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

Re: [Pharo-users] How to write out simple Json?

2019-03-01 Thread Sven Van Caekenberghe
> On 28 Feb 2019, at 22:35, Tim Mackinnon wrote: > > Sven- thinking a bit more > >> On 28 Feb 2019, at 13:59, Sven Van Caekenberghe wrote: >> >> This is wrong !! >> >> Think about it, what would then happen with a mixed list ? >> >> { #key->#value. 1. true } >> >> That would generate

Re: [Pharo-users] How to write out simple Json?

2019-03-01 Thread Sven Van Caekenberghe
I would use any of the following: ex := { #track->#pharo. #language->#smalltalk. #exercises->{ #slug->'hello'. #id->55. #topics->#('a' 'b' 'c') } asDictionary } asDictionary. ex := { #track->#pharo. #language->#smalltalk. #exercises->({ #slug->'hello'. #id->55.

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Jimmie Houchin
I don't know if you really need OrderedDictionary or not. But I am a big fan of and use all the time simple Arrays or OrderedCollection of pairs. It is neat, clean and readable. ex := Dictionary newFromPairs: {     'track'. 'pharo.     'language'. 'smalltalk'.     'exercises'. Dictionary

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Tim Mackinnon
Sven- thinking a bit more > On 28 Feb 2019, at 13:59, Sven Van Caekenberghe > wrote: > > This is wrong !! > > Think about it, what would then happen with a mixed list ? > > { #key->#value. 1. true } > > That would generate invalid JSON. I actually went and tried my

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Henrik Sperre Johansen
Tim Mackinnon wrote > Just to add more flavour to this - it seems quite wordy that we have to do > this (or equivalent) to write some config. > > ex := OrderedDictionary new > at: 'track' put: 'pharo'; > at: 'language' put: 'smalltalk'; > at: 'exercises' put: ( >

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Richard O'Keefe
1. A JSON "object" corresponds to some kind of dictionary in Smalltalk. 2. {#a -> 1. #b -> 2} is NOT A DICTIONARY. It is an Array of Associations. 3. {#a -> 1. #b -> 2} asDictionary *is* a dictionary. 4. My Smalltalk allows #{#a -> 1. #b -> 2} -- how could I let it be less

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Sven Van Caekenberghe
This is wrong !! Think about it, what would then happen with a mixed list ? { #key->#value. 1. true } That would generate invalid JSON. > On 28 Feb 2019, at 14:56, Tim Mackinnon wrote: > > As I merrily chat to myself - I noticed that STONWriter almost does what I > need - it just complains

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Sven Van Caekenberghe
I really don't understand. JSON needs Dictionaries and Arrays (or other Sequenceable Collections). That has nothing to do with Pharo or how NeoJSON or STONJSON are implemented - it is what defines JSON. Of course, compatible objects work as well (NeoJSONObject is an example). You could make

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Tim Mackinnon
As I merrily chat to myself - I noticed that STONWriter almost does what I need - it just complains in #writeAssociation: so I make a subclass STONJSONWriter and override: writeAssociation: association “don’t smack me…. jsonMode ifTrue: [ self error: 'wrong

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Tim Mackinnon
Just to add more flavour to this - it seems quite wordy that we have to do this (or equivalent) to write some config. ex := OrderedDictionary new at: 'track' put: 'pharo'; at: 'language' put: 'smalltalk'; at: 'exercises' put: ( OrderedDictionary new

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Tim Mackinnon
Hi Sven - is there no convenience shortcut we can use in our code to make this less wordy when we are specifying it? E.g. the following is very convenient to write - but doesn’t work (as you have $‘ and not $“ ) ex := { 'track'-> 'pharo'. 'language' -> 'smalltalk'.

Re: [Pharo-users] How to write out simple Json?

2019-02-28 Thread Sven Van Caekenberghe
STONJSON toString: { #id->1. #name->'tim' } asDictionary. JSON cannot deal with Associations by themselves. > On 28 Feb 2019, at 14:05, Tim Mackinnon wrote: > > I am stumped about how to write out some simple json (for a config file). I > didn't think I need Neo, and STONJSON would be fine

[Pharo-users] How to write out simple Json?

2019-02-28 Thread Tim Mackinnon
I am stumped about how to write out some simple json (for a config file). I didn't think I need Neo, and STONJSON would be fine but it seems like creating items like: { 'id'-> self id. 'name' -> self name } gives an error about the association. I think you have to do: { ('id'-> self id)