@@ -50,7 +50,7 @@ NeoJSONObject class >> fromString: string [
5050 " Parse string as JSON, so that maps become instances of me"
5151
5252 ^ (NeoJSONReader on: string readStream)
53- mapClass: NeoJSONObject ;
53+ mapClass: self ;
5454 propertyNamesAsSymbols: true ;
5555 next
5656]
@@ -59,10 +59,25 @@ NeoJSONObject class >> fromString: string [
5959NeoJSONObject >> at: key [
6060 " I return nil for missing keys.
6161 My superclass would signal a KeyNotFound."
62-
62+
6363 ^ self at: key ifAbsent: [ nil ]
6464]
6565
66+ { #category : #' nested dictionaries' }
67+ NeoJSONObject >> at: firstKey at: secondKey [
68+ " I return nil for missing keys.
69+ My superclass would signal a KeyNotFound."
70+
71+ ^ self atPath: { firstKey. secondKey }
72+ ]
73+
74+ { #category : #' nested dictionaries' }
75+ NeoJSONObject >> at: firstKey at: secondKey put: value [
76+ " Store value under secondKey in nested object under firstKey, create new level when needed"
77+
78+ ^ self atPath: { firstKey. secondKey } put: value
79+ ]
80+
6681{ #category : #accessing }
6782NeoJSONObject >> at: key ifPresent: aPresentBlock ifAbsentPut: anAbsentBlock [
6883 " Lookup the given key in the receiver. If it is present, answer the
@@ -71,7 +86,7 @@ NeoJSONObject >> at: key ifPresent: aPresentBlock ifAbsentPut: anAbsentBlock [
7186
7287 " Overwritten to patch a bug in the superclass implementation in Pharo 7 and 8.
7388 This problem was fixed in Pharo 9 where this overwrite is no longer necessary but harmless."
74-
89+
7590 ^ self
7691 at: key
7792 ifPresent: aPresentBlock
@@ -81,19 +96,19 @@ NeoJSONObject >> at: key ifPresent: aPresentBlock ifAbsentPut: anAbsentBlock [
8196{ #category : #accessing }
8297NeoJSONObject >> atPath: keyCollection [
8398 " Use each key in keyCollection recursively, stop when nil is encountered"
84-
99+
85100 | value |
86101 value := self .
87102 keyCollection do: [ :each |
88103 value := value at: each.
89104 value ifNil: [ ^ nil ] ].
90- ^ value
105+ ^ value
91106]
92107
93108{ #category : #accessing }
94109NeoJSONObject >> atPath: keyCollection put: newValue [
95110 " Use each key in keyCollection recursively, create new levels when needed"
96-
111+
97112 | target |
98113 keyCollection ifEmpty: [ ^ self ].
99114 target := self .
@@ -108,7 +123,7 @@ NeoJSONObject >> atPath: keyCollection put: newValue [
108123NeoJSONObject >> doesNotUnderstand: message [
109124 " Overwritten so that 'self foo' becomes 'self at: #foo'
110125 and 'self foo: 1' becomes 'self at: #foo put: 1' except that self is returned"
111-
126+
112127 | key |
113128 key := message selector.
114129 key isUnary
@@ -121,7 +136,7 @@ NeoJSONObject >> doesNotUnderstand: message [
121136{ #category : #accessing }
122137NeoJSONObject >> name [
123138 " Overwritten to make this accessor available as key"
124-
139+
125140 ^ self at: #name
126141]
127142
@@ -131,15 +146,15 @@ NeoJSONObject >> printOn: stream [
131146
132147 [ (NeoJSONWriter on: stream) nextPut: self ]
133148 on: Error
134- do: [ :exception |
149+ do: [ :exception |
135150 stream
136151 nextPutAll: ' Error printing JSON: ' ;
137- nextPutAll : exception printString ]
152+ print : exception ]
138153]
139154
140155{ #category : #evaluating }
141156NeoJSONObject >> value [
142157 " Overwritten to make this accessor available as key"
143-
158+
144159 ^ self at: #value
145160]
0 commit comments