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 ?

Answers


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


Need Your Help

Subquery with multiple select statements

sql subquery correlated-subquery

to check the subquery having multiple select statement inside 'not in' condition

java: try finally blocks execution

java try-catch finally

I am confused about the try-finally execution when there exists return; in the try block. In my understanding, the finally block will always be executed, i.e. before returning to the calling method.