Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python object output to PHP Array

Tags:

arrays

object

php

After reading related questions, I have to mention my question here.

I'm running a python script to fetch the data from Google place API. Somehow managing with PHP, I converted list of objects into below output:

[   {
    'fri_hours': "b'9:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'wed_hours': "b'9:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'sun_hours': "b'Closed'",
    'photo_reference': '',
    'phone_number': b'+1 212-354-1006',
    'state': b'New York',
    'country': b'United States',
    'place_id': 'ChIJ8cFYDKpZwokRpC04mEYm20s',
    'thu_hours': "b'9:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'business_name': b'CarLeo Hair Salon',
    'address': b'22West 38th Street',
    'city': b'New York',
    'mon_hours': "b'9:00 AM \\xe2\\x80\\x93 6:00 PM'",
    'type': 'beauty salon',
    'sat_hours': "b'Closed'",
    'tue_hours': "b'9:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'postal_code': '10018',
    'website': 'http://www.carleohairsalon.com/',
    'rating': 4.6   } ][   {
    'fri_hours': "b'8:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'wed_hours': "b'8:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'sun_hours': "b'Closed'",
    'photo_reference': 'CmRaAAAAe8XIMwcPu3uhohYjJ-dQt69rtZ-x2XJ-I28USF-LphSaVH4Gt-_JUmB06TGnOKKmAqSjnhGuFqUKb7pitV1twViGVE7znVYLSdRYZ72LKjtlXT47YapfEreCmd9lK1R8EhCEJ2Pb2Fpe2sbfbOF3hXgmGhRaJbdZKiF8S0GxdzVj3r7mQphVtw',
    'phone_number': b'+1 212-688-6498',
    'state': b'New York',
    'country': b'United States',
    'place_id': 'ChIJ0SFDYuVYwokRXJvyfmR9kec',
    'thu_hours': "b'8:00 AM \\xe2\\x80\\x93 8:00 PM'",
    'business_name': b'Mizu Salon',
    'address': b'505Park Avenue',
    'city': b'New York',
    'mon_hours': "b'10:00 AM \\xe2\\x80\\x93 6:00 PM'",
    'type': 'beauty salon',
    'sat_hours': "b'9:00 AM \\xe2\\x80\\x93 7:00 PM'",
    'tue_hours': "b'8:00 AM \\xe2\\x80\\x93 7:00 PM'",
    'postal_code': '10022',
    'website': 'http://www.mizuforhair.com/',
    'rating': 4.4   } ]

Now, simply I want to convert above output into a single array containing sub-arrays of the object using PHP

I have tried with using foreach loop but getting the same output.

like image 790
Dhaval Avatar asked Apr 25 '26 22:04

Dhaval


1 Answers

In your python script do something like

import json
#some code here
jsonStr = json.dumps(myListFromGooglePlaces)
#whatever you do to get it to php

and then as mentioned in my comment above

$arr = json_decode($json, true);

I hope that works for you.

like image 118
Domenik Reitzner Avatar answered Apr 28 '26 11:04

Domenik Reitzner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!