wp_json_file_decode()
Reads and decodes (parses) the specified JSON file.
Used By: register_block_type_from_metadata()
No Hooks.
Returns
Mixed.
-
Object/array/string/number/bool- data encoded in the JSON file as an object or associative array. null- will return null if the file is not found, and will log the messageFile %s doesn't exist!in the error log. It will also return null if the file's contents cannot be decoded and will log the errorError when decoding a JSON file at path %1$s: %2$s.
Usage
wp_json_file_decode( $filename, $options );
- $filename(string) (required)
- Path to the JSON file.
- $options(array)
Options used with json_decode().
Default: array()
-
associative(true|false)
true- JSON objects will be returned as associative arrays.false- JSON objects will be returned as objects.
Default: false
-
Examples
#1 Get the contents of the json file as an associative array
$path_file = '/path/to/data.json'; $decoded_file = wp_json_file_decode( $path_file, [ 'associative' => true ] );
Changelog
| Since 5.9.0 | Introduced. |