How to load a json file in php code to prepare it for HTTP POST?
I have a .json file on disk. I would like to load it on my php code so that i can make an HTTP POST request with it.
I have done exactly the same with XML like this :
$file = 'http://localhost/myServer/test.xml'; $xml_builder = simplexml_load_file($file))
Then i use the $xml_builder variable to send the XML with CURL.
How can i do exactly the same with JSON ?
I think you need to do something like:
$variable = file_get_contents('http://example.com/data.json'); $decoded = json_decode($variable);
You need to decode it because you are getting it as a string in the $variable and then use it as you want