I have a script in Python pulling information from one service and a script in PHP pulling from another. I'd like to parse and compare the data from both, so obviously I need the information to be in the same format.
The Python script returns a text file in JSON format. Here's a small snippet. Disregard the information inside. I just want to show the formatting.
{
"category": 0,
},
"cluster_seed": "24",
"clusters": {
"clusters": [
{
"center": {
"000002": [
"massachusetts",
"new hampshire",
"new jersey"
],
"000003": [
"Windows",
"OSX"
]
}
etc...
However, the PHP script returns information like this:
Array
(
[0] => Array
(
[name] => John Smith
[engagementScore] => 0
[firstActivity] => 1386555168108
[lastActivity] => 1386555168108
[attributes] => Array
(
[_deviceType] => Tablet
[_os] => Android
[_browser] => Chrome
)
[segmentMemberships] => Array
(
[0] => Array
(
[segmentationName] => example
[segementationId] => example
)
)
I'm not really sure what's going on here. I guess it's printing as a PHP object/array rather than a raw JSON file? I would like it to be formatted exactly as the first snippet is. This is the code in my PHP that pulls this information:
$response = curl_exec($session);
$info = curl_getinfo($session);
$body = substr($response, $info['header_size']);
$decoded_result = json_decode($body, true);
I thought that json_decode
would print it in the same format but clearly that's not the case. I tried json_encode
but that just prints an enormous block of completely illegible information.
Is there any way to print this information in the same format that the first script returns so I can compare the two? Thanks!