Skip to content

[12.x] Add fromJson() to Arr helper #56708

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

Open
wants to merge 8 commits into
base: 12.x
Choose a base branch
from

Conversation

shaedrich
Copy link
Contributor

Counterpart of #56697, so to speak

Examples

Arr::fromJson('}', false, 512, 0); // ❌ Throws 'Please provide a valid JSON: Syntax error'
Arr::fromJson("[\"\u{D800}\"]", false, 512, 0); // ❌ Throws 'Please provide a valid JSON: Malformed UTF-8 characters, possibly incorrectly encoded'
Arr::fromJson('[[[[]]]]', false, 2, 0); // ❌ Throws 'Please provide a valid JSON: Maximum stack depth exceeded'
Arr::fromJson('null', false, 512, 0); // ❌ Throws 'The given JSON cannot be parsed into an array: null given instead'
Arr::fromJson('42', false, 512, 0); // ❌ Throws 'The given JSON cannot be parsed into an array: int given instead'
Arr::fromJson('42.1', false, 512, 0); // ❌ Throws 'The given JSON cannot be parsed into an array: float given instead'
Arr::fromJson('"foo"', false, 512, 0); // ❌ Throws 'The given JSON cannot be parsed into an array: string given instead'
Arr::fromJson('true', false, 512, 0); // ❌ Throws 'The given JSON cannot be parsed into an array: bool given instead'
Arr::fromJson('{"foo": "bar"}', false, 512, 0); // ❌ Throws 'The given JSON cannot be parsed into an array: stdClass given instead'

Arr::fromJson('[1, 2, 3]', false, 512, 0); // ✔️ [1, 2, 3]
Arr::fromJson('[1, 2, 3]', null, 512, JSON_OBJECT_AS_ARRAY); // ✔️ [1, 2, 3]
Arr::fromJson('[1, 2, 3]', true, 512, 0); // ✔️ [1, 2, 3]
Arr::fromJson('{"foo": "bar"}', null, 512, JSON_OBJECT_AS_ARRAY); // ✔️ ["foo" => "bar"]
Arr::fromJson('{"foo": "bar"}', true, 512, 0); // ✔️ ["foo" => "bar"]

@shaedrich shaedrich changed the title Add fromJson() to Arr helper [12.x] Add fromJson() to Arr helper Aug 21, 2025
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

Successfully merging this pull request may close these issues.

1 participant