Make WordPress Core

#56864 closed feature request (wontfix)

I want to put comments in theme.json.

Reported by: nendeb55's profile nendeb55 Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.2
Component: Themes Keywords:
Focuses: Cc:

Description

theme.json is getting complicated.
It would be helpful to have a comment box to comment out the code or to review it later or have others review the code.Currently theme.json has an error when a comment is entered.

So I would like to be able to put comments in theme.json and expect it to load correctly.

https://github.com/WordPress/wordpress-develop/blob/70dedb086602287f4e0ee97fbf477adda8310963/src/wp-includes/functions.php#L4545
Simple method with no consideration of security, null, etc.

<?php
//$decoded_file = json_decode( file_get_contents( $filename ), $options['associative'] );

$filedata = file_get_contents( $filename );
$filedata = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $filedata  );
$decoded_file = json_decode( $filedata , $options['associative'] );

Change History (2)

#1 @jorbin
16 months ago

  • Keywords close added

JSON doesn't support comments. It's unfortunate, but if something like this were to be put in place, theme.json would not be interoperable JSON. When someone sees the .json extension they assume it is JSON that can be parsed and worked with as JSON. That isn't something I think we should break. As such, i think this should be closed as wontfix.

If an individual or team is facing challenges here, I think it might be better for them to use something like jsonc and to have a build process convert it to json.

#2 @desrosj
14 months ago

  • Component changed from General to Themes
  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

It's been 3 months without any additional reasoning as to why this is important to consider in Core.

To add to @jorbin's points above, there's also JSON Schema that tries to address this.

Note: See TracTickets for help on using tickets.