Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping a nested Json object #8

Open
kurucu opened this issue May 24, 2024 · 0 comments
Open

Mapping a nested Json object #8

kurucu opened this issue May 24, 2024 · 0 comments

Comments

@kurucu
Copy link

kurucu commented May 24, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant