-
Couldn't load subscription status.
- Fork 8k
[RFC] Add json_encode indent parameter #7093
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
Closed
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
40747f4
Initial work for json_encode indentation option
tdgroot 2bf91bd
Add string|int support for json_encode indent param
tdgroot 98c208b
Fix formatting
tdgroot 9d8a35a
Fix potential segfault
tdgroot 727713d
Fix pointer initial value
tdgroot 548d034
Update json.stub.php
tdgroot 5566e76
Add error handling and use zend_string*
tdgroot d808cdc
Update ext/json/json.c
f2554ec
Update ext/json/json.c
f5b8fc7
Update ext/json/json.c
7725e9a
Early exit in php_json_pretty_print_indent
tdgroot c34482b
Move indent_str init to implicit function
tdgroot 1005827
Cleanup json.c and add comments
tdgroot 7345d24
Update ext/json/json.c
fada489
Merge branch 'master' into json_encode_indentation
tdgroot d416b4f
Simplify json_encode indent parameter
tdgroot 13d138a
Add missing EOF to testfile
tdgroot f36942d
Remove unused global
tdgroot fcc1045
Update ext/json/json.c
tdgroot e7d7b4b
Update ext/json/tests/json_encode_pretty_print_indent_error.phpt
tdgroot eea6007
fixup! Update ext/json/tests/json_encode_pretty_print_indent_error.phpt
tdgroot 574dc0c
Make the indent of internal json_encode more coherent with userspace …
tdgroot abaa117
Merge branch 'master' of github.com:php/php-src into json_encode_inde…
tdgroot b8b941d
Update json_arginfo.h
tdgroot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --TEST-- | ||
| json_encode() with JSON_PRETTY_PRINT with 2 spaces string indentation | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $data = [ | ||
| 'key' => 4, | ||
| 'other_key' => [0, 1, 2, 3] | ||
| ]; | ||
|
|
||
| echo json_encode($data, JSON_PRETTY_PRINT, 512, 2); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| { | ||
| "key": 4, | ||
| "other_key": [ | ||
| 0, | ||
| 1, | ||
| 2, | ||
| 3 | ||
| ] | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --TEST-- | ||
| json_encode() with JSON_PRETTY_PRINT with negative indentation | ||
| --FILE-- | ||
| <?php | ||
| echo "*** Testing json_encode() : error conditions ***\n"; | ||
|
|
||
| echo "\n-- Testing json_encode() function (JSON_PRETTY_PRINT) with negative indentation --\n"; | ||
tdgroot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $data = [ | ||
| 'key' => 4, | ||
| 'other_key' => [0, 1, 2, 3] | ||
| ]; | ||
|
|
||
| try { | ||
| echo json_encode($data, JSON_PRETTY_PRINT, 512, -2); | ||
| } catch (\ValueError $e) { | ||
| echo $e->getMessage() . \PHP_EOL; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| *** Testing json_encode() : error conditions *** | ||
|
|
||
| -- Testing json_encode() function (JSON_PRETTY_PRINT) with negative indentation -- | ||
| json_encode(): Argument #4 ($indent) must be a number greater than or equal to 0 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.