php / php/php-src

JSON pretty printing indentation using tabs or double spaces

Open
#8,864 8 comments 13 reactions 1 assignee View on GitHub

@bukka is already working on this.

Since Jul 29, 2022.

Extension: json Feature Status: Requires RFC
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The current indentation of pretty printed JSON with json_encode() is using 4 bytes per level.
I feel we are lacking the ability to choose intendation type, i.e. for optimization.

Example:

  • Tab (1 bytes)
  • Two spaces (2 bytes)
  • Four spaces (4 bytes)

Maybe by setting a flag to either:
JSON_PRETTY_PRINT
JSON_PRETTY_PRINT_TABS
JSON_PRETTY_PRINT_DOUBLE_SPACES

I know that we can preg_replace() it the way we want. But why waste resources if we could have it at the core.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.