Skip to content

json_encode(json_decode(json_encode($array))); shouldn't be necessary #18598

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

Closed
Hanzerik opened this issue May 19, 2025 · 2 comments
Closed

json_encode(json_decode(json_encode($array))); shouldn't be necessary #18598

Hanzerik opened this issue May 19, 2025 · 2 comments

Comments

@Hanzerik
Copy link

Description

to get from

$array = ['foo' => "a", 'bar' => "b"];

to:

{
    "foo": "a",
    "bar": "b"
}

We currently need to create the following helperfunction:

    function arrayToJsonObject(array $array)
    {
       return  json_encode(json_decode(json_encode($array)));
    }

Would be really cool if that wasn't necessary

@Hanzerik Hanzerik changed the title json_encode(json_decode(json_encode($array))); shouldn't be necesary json_encode(json_decode(json_encode($array))); shouldn't be necessary May 19, 2025
@iluuu1994
Copy link
Member

Hi @Hanzerik 👋 Your example doesn't reproduce. https://3v4l.org/Mp4B2 Can you clarify?

@Hanzerik
Copy link
Author

Nevermind. my imput was [['foo' => 'a', 'bar' => 'b']]

@TimWolla TimWolla closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants