I have been working on a trivia game plugin for our website. I first built the trivia outside of WordPress to get the basics down and working before complicating things with WP. I got the thing finished and then started working on converting it to a plugin. For some reason, using json_decode with the .json file does not work in WordPress.
I know that the JSON file is valid because it works fine outside of WP and I've run it through several validators out on the web.
This is what I'm using in the plugin:
$json_data = plugins_url('data/questions.json', __FILE__ );
$parsed_data = json_decode($json_data,true);
Inside of the WP pluging, sending through var_dump results in NULL. Sending it through json_last_error() gives: JSON Error: - Syntax error, malformed JSON
Strangely, taking the exact content of the file and using:
$parsed_data = json_decode('pasted json code in here');
works fine, it only seems to think there is a problem with the JSON when it is in a separate file. Is there something about plugins_url() that could be messing with it? I'm out of ideas as to what is causing this problem.
Thanks!
Note: I've tried some of the suggestions out on the web for using preg_replace() with no luck, also - the file reports that it is ASCII and not UTF-8.