rfc:json_encode_indentation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:json_encode_indentation [2021/06/03 15:23] โ€“ tdgrootrfc:json_encode_indentation [2022/07/04 19:37] โ€“ Adjusted voting open/close dates tdgroot
Line 4: Line 4:
   * Author: Timon de Groot, tdegroot96@gmail.com   * Author: Timon de Groot, tdegroot96@gmail.com
   * Implementation: https://github.com/php/php-src/pull/7093   * Implementation: https://github.com/php/php-src/pull/7093
-  * Status: Draft+  * Status: Voting
  
 ===== Introduction ===== ===== Introduction =====
Line 10: Line 10:
  
 ===== Proposal ===== ===== Proposal =====
-Introducing a 4th parameter, called //indent//. The type of the parameter is string|int and its default value is 4.+Introducing a 4th parameter, called //indent//. The type of the parameter is int and its default value is 4.
  
-When a string is passedthat character sequence will be used for indentation, where it normally would be '    ' (4 spaces). Users passing a string must be aware that usage of invalid JSON characters in the indentation value will natually cause invalid formatted JSON data.+By defaultan indentation of 4 spaces will be applied, just like the original //json_encode// behaviour with the //JSON_PRETTY_PRINT// option
  
-When an int is passed, an indentation of N spaces will be applied.+When the //indent// parameter is passed a different value, an indentation of N spaces will be applied.
  
 <code php> <code php>
Line 24: Line 24:
 echo json_encode(['behavior' => 'default'], JSON_PRETTY_PRINT) . PHP_EOL; echo json_encode(['behavior' => 'default'], JSON_PRETTY_PRINT) . PHP_EOL;
 echo json_encode($data, JSON_PRETTY_PRINT, 512, 2) . PHP_EOL; echo json_encode($data, JSON_PRETTY_PRINT, 512, 2) . PHP_EOL;
-echo json_encode(['unicode' => "supported"], JSON_PRETTY_PRINT, 512, '๐Ÿš€๐Ÿš€') . PHP_EOL; 
-echo json_encode(['tabs' => "better"], JSON_PRETTY_PRINT, 512, "\t") . PHP_EOL; 
  
 ?> ?>
Line 39: Line 37:
     2     2
   ]   ]
-} 
-{ 
-๐Ÿš€๐Ÿš€"unicode": "supported" 
-} 
-{ 
- "tabs": "better" 
 } }
 </code> </code>
Line 59: Line 51:
 ===== Patches and Tests ===== ===== Patches and Tests =====
 Tests are written with the RFC Tests are written with the RFC
 +
 +===== Vote =====
 +
 +Voting opened on 2022-07-04 and closes on 2022-07-18.
 +
 +<doodle title="Add support for changing the JSON indentation amount?" auth="tdgroot" voteType="single" closed="false">
 +   * Yes
 +   * No
 +</doodle>
 +
rfc/json_encode_indentation.txt ยท Last modified: 2022/07/19 15:23 by cmb

๏ปฟ