Mapping a nested Json object
kurucu opened this issue · comments
What's the best way to map a nested json object?
Imagine this response shown here: https://stytch.com/docs/b2b/api/create-organization
Inside that Json object is an Organisation, which is the only thing I need to map.
Currently, I json_decode the response to test for errors and raise exceptions based on any error object. This means I have access to an organisation object already ($data->organisation).
I don't think re-json_encoding that Organisation object is the way forward, only to pass it to Json-Mapper to do it all again.
So from what I can see, I'm either petitioning for:
- mapToObject() to be made public, so I can pass my object straight to it; or,
- map() gets a new, nullable, argument that specifies the path to the object to map.
Am I seeing this from the wrong angle? All thoughts appreciated!
Edit: similar question, but for when an array of objects is returned.
Edit2: Would it be typical to leave json-mapper alone, and create a PHP object per API Response type?