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": "smalltalk","exercises": ["slug": "hello","id": 
55,"topics": ["a","b","c"]]]'

You see this is wrong, do you ?

BTW, the package you mentioned did not load in Pharo, it can if you make the 
following change:

Json class>>#initialise
        "Json initialize."
        
        escapeArray := Array new: 128.
        (0 to: 31), #(127) do: [ :each |
                escapeArray at: each + 1 put: '\u', (each printStringHex 
padLeftTo: 4 with: $0) ].
        {
                $" -> '\"'.
                $\ -> '\\'.
                Character backspace -> '\b'.
                Character lf -> '\n'.
                Character newPage -> '\f'.
                Character cr -> '\r'.
                Character tab -> '\t'.
        } do: [ :each |
                escapeArray at: each key asciiValue + 1 put: each value ].

> On 2 Mar 2019, at 06:37, Paul DeBruicker <pdebr...@gmail.com> wrote:
> 
> 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 e.g.
> 
> Object>>#asJsonString
>         ^JSON render: self
> 
> 
> 
> 
> 
> 
> Tim Mackinnon wrote
>>> On 1 Mar 2019, at 10:35, Sven Van Caekenberghe &lt;
> 
>> sven@
> 
>> &gt; 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 ;)
>> 
>> 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.
>> 
>> Tim
> 
> 
> 
> 
> 
> --
> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html


Reply via email to