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

[Feature] Allow dot-notation for JSON paths #9

Open
szainmehdi opened this issue Oct 6, 2022 · 4 comments
Open

[Feature] Allow dot-notation for JSON paths #9

szainmehdi opened this issue Oct 6, 2022 · 4 comments

Comments

@szainmehdi
Copy link
Contributor

Using the example definition in the README, it would be great (and familiar to Laravel users) to define nested JSON mappings using dot-notation.

class Schedule
{
    use JsonSerialize;

    #[Json('data.start')]
    protected int $start;

    #[Json('data.end')]
    protected int $end;

    public function __construct(int $start, int $end)
    {
        $this->start = $start;
        $this->end = $end;
    }
}
@khepin
Copy link
Collaborator

khepin commented Oct 6, 2022

My problem with dot notation is that this:

{
    "data": {
        "name": "bob"
    },
    "data.name": "alice"
}

is valid json

@khepin
Copy link
Collaborator

khepin commented Oct 6, 2022

It's also inconsistently implemented even within laravel itself. Arr::get vs. data_get.

@szainmehdi
Copy link
Contributor Author

Oh that's a good point about data.name being a valid JSON key.

Generally speaking I like the simplicity of dot-notation, and it saves a few keystrokes. But I understand why it may not make sense for this library 👍

@khepin
Copy link
Collaborator

khepin commented Oct 14, 2022

Actually the real issue when using dot notation wouldn't be deserializing but serializing. IE: where do I put a value that has a path of data.name? When de-serializing you could try both, when serializing you're .... kinda stuck.

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

2 participants