how to get json file in wordpress template

I am trying to get data from JSON file in Wordpress template using file_get_contents But can not get the file

$data = file_get_contents("../assets/data2.json");
$arr = json_decode($data, true);

Facing this error while var_dump $data

object(WP_Error)#825 (2) { ["errors"]=> array(1) { ["http_request_failed"]=> array(1) { [0]=> string(29) "A valid URL was not provided." } } ["error_data"]=> array(0) { } }

My data2.json file is in the assets folder and trying from templates folder in theme folder in wordpress.

Topic wp-filesystem json themes Wordpress

Category Web


file_get_contents() is usually blocked to fetching content from URLs for safety reasons. You should provide a local server path. In alternative use wp_remote_get()

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.