Jump to content

JSON import


Recommended Posts

And isn't it faster to convert json feed to xml?

$getJson = file_get_contents('myjson.json');
$array = json_decode($getJson, true);

$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($array, array($xml, 'addChild'));

print $xml->asXML();

 

Edited by knacky (see edit history)
Link to comment
Share on other sites

hello, thanks for answering, I imagine that it would also be faster to convert to csv, but we are talking about one more step, the client downloads the JSON from a site and wants this file to remain in a cron task for updates, now well I don't know if the same technique that is used to download those products in JSON gives you the ability to say that you want it in XML. you want is to avoid one more step

Link to comment
Share on other sites

After all, you can process a JSON file directly.

/*
{
    "items": [
        {
            "product": {
                "googleId": "1111111111111",
                "author": {"name": "product one, "reference": "ABCD123","price": "123.85"}
            }
        }
    ]
}
*/

$getJson = file_get_contents('myjson.json');
$array = json_decode($getJson, true);

foreach ($array>items as $item) {
   var_dump($item->product->reference);
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...