It's not possible to tell json_encode what indentation level should be used when using the JSON_PRETTY_PRINT option (2, 4, 8, etc). When generating JSON files which can be
used/read/edited by users, indentation starts to become a relevant topic.

- JavaScript has a function called JSON.stringify wich accepts the optional 'space' parameter   - See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify - Python has a function called json.dump which accepts the optional 'indent' parameter
  (which also controls pretty printing)
  - See https://docs.python.org/3/library/json.html#basic-usage

I would like to create an RFC draft to implement an 'indent' parameter.
Before I start a draft, I need to know if this is a good idea, so I start with a few questions.

1. What do you think of adding an 'indent' parameter?
2. How would that parameter work when the JSON_PRETTY_PRINT option is not passed?
3. What do you think of adding json_encode options instead, like
      JSON_PRETTY_PRINT_INDENT_2 and JSON_PRETTY_PRINT_INDENT_4?

Looking forward to you replies and feedback!

--

Kind regards,

Timon de Groot

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to