wp_json_file_decode()
Reads and decodes a JSON file.
Used By: register_block_type_from_metadata()
No Hooks.
Return
Mixed
. Returns the value encoded in JSON in appropriate PHP type. null is returned if the file is not found, or its content can't be decoded.
Usage
wp_json_file_decode( $filename, $options );
- $filename(string) (required)
- Path to the JSON file.
- $options(array)
Options to be used with json_decode().
Default: array()
- associative(true|false)
Optional. When true, JSON objects will be returned as associative arrays. When false, JSON objects will be returned as objects.
Default: false
- associative(true|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. |