NeoJSON Parsing Nested Objects
I'm wrapping the Digital Ocean API. This particular response has a status, and an array of droplet sizes. For example: '{"status":"OK","sizes":[{"id":66,"name":"512MB","slug":"512mb","memory":512,"cpu":1,"disk":20,"cost_per_hour":0.00744,"cost_per_month":"5.0"},{"id":63,"name":"1GB","slug":"1gb","memory":1024,"cpu":1,"disk":30,"cost_per_hour":0.01488,"cost_per_month":"10.0"}]}' As a start, I did: reader := NeoJSONReader on: jsonString readStream. reader for: DoResponse customDo: [ :m | m decoder: [ :dict | DoResponse new status: (dict at: 'status'); contents: (dict at: 'sizes') ] ]. response := reader nextAs: DoResponse. response isOk ifFalse: [ self error: 'Query failed!' ]. ^ response contents. However, the size objects are still plain dictionaries. I'd like to convert them to DropletSize objects. And I'd rather leverage NeoJSON than implement a custom DropletSize fromDictionary: if possible. What's the best way to handle this? Thanks. ----- Cheers, Sean -- View this message in context: http://forum.world.st/NeoJSON-Parsing-Nested-Objects-tp4753695.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Sean P. DeNigris wrote
I'd like to convert them to DropletSize objects
Duh :-P reader for: DoResponse do: [ :m | m mapInstVar: #status. (m mapInstVar: #contents to: #sizes) valueSchema: #ArrayOfDropletSizes ]. ----- Cheers, Sean -- View this message in context: http://forum.world.st/NeoJSON-Parsing-Nested-Objects-tp4753695p4753696.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
On 09 Apr 2014, at 19:28, Sean P. DeNigris <sean@clipperadams.com> wrote:
Sean P. DeNigris wrote
I'd like to convert them to DropletSize objects
Duh :-P
reader for: DoResponse do: [ :m | m mapInstVar: #status. (m mapInstVar: #contents to: #sizes) valueSchema: #ArrayOfDropletSizes ].
BTW, I did some recent enhancements to NeoJSON mapping that could be interesting. http://www.smalltalkhub.com/#!/~SvenVanCaekenberghe/Neo/commits like #nextPut:as:
2014-04-09 14:56 GMT-03:00 Sven Van Caekenberghe <sven@stfx.eu>:
On 09 Apr 2014, at 19:18, Sean P. DeNigris <sean@clipperadams.com> wrote:
I'm wrapping the Digital Ocean API.
Cool !
+1 I use it for my Pharo hosting too (plus a JIRA instance on other droplet). Anybody using Supervisord or anything similar tool to "manage" pharo instances? Regards!
Esteban A. Maringolo wrote
I'm wrapping the Digital Ocean API. Cool ! +1
The embryo is alive. See documentation at http://smalltalkhub.com/#!/~SeanDeNigris/DigitalOcean A few supported operations: DoDroplet allActive. DoDroplet allActive detect: [ :e | e name = 'mycooldomain.org' ]. DoDropletSize all. DoDropletSize named: '512MB' ----- Cheers, Sean -- View this message in context: http://forum.world.st/NeoJSON-Parsing-Nested-Objects-tp4753695p4753749.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
It's basic but it works. :) THanks sean! Esteban A. Maringolo 2014-04-09 18:07 GMT-03:00 Sean P. DeNigris <sean@clipperadams.com>:
Esteban A. Maringolo wrote
I'm wrapping the Digital Ocean API. Cool ! +1
The embryo is alive. See documentation at http://smalltalkhub.com/#!/~SeanDeNigris/DigitalOcean
A few supported operations: DoDroplet allActive. DoDroplet allActive detect: [ :e | e name = 'mycooldomain.org' ]. DoDropletSize all. DoDropletSize named: '512MB'
----- Cheers, Sean -- View this message in context: http://forum.world.st/NeoJSON-Parsing-Nested-Objects-tp4753695p4753749.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
participants (3)
-
Esteban A. Maringolo -
Sean P. DeNigris -
Sven Van Caekenberghe