Jeffail/gabs

Recursively parsing a http response

Opened this issue · 2 comments

Thanks for your awesome library :) and I am sure I'm just being dense so apologies in advance; but I am struggling with using gabs to parse a http response recursively.

https://play.golang.org/p/OpCQE8YKDzk

I am trying to iterate through a http response, building new gabs containers as I go, with changed keys and values, and ultimately returning a new container; however I'm only able to get one level deep and so I assume I am using ChildrenMap incorrectly.

Is there a recommended way to recursively change arbitrary json? I'd appreciate it if you could tell me if I missing something obvious here.

Hey @DanielHouston, what do you want the output to look like? Made a few adjustments and got as far as: https://play.golang.org/p/11yEBP8sTmm

The main issue is that ChildrenMap only returns >0 children when targetting an object. In order to iterate arrays you need to use Children, so if you want to pass in the root object and have it walk the array at result you also need to check for Children() > 0 (or just to a type switch on inputMap.Data()).

Thanks for the lightening fast response @Jeffail - Your adjustments seem to be pretty much what I want here. I can use this to apply any transformation to the keys regardless of how nested they are.
I think moving to switching on types would be cleaner here, am I right that each entry in the results array would need another call to parseResp and and ArrayAppend in the same way each of the objects are handled?