1

Google Maps is returning what https://jsonlint.com/ is flagging as invalid JSON. It has a problem with escaped single-quotes in reviews people have left. So something like:

{
  "author_name": "Darrell McClendon",
  "author_url": "https://www.google.com/maps/contrib/105899976805332994558/reviews",
  "language": "en",
  "profile_photo_url": "https://lh4.googleusercontent.com/-XmJwNWWFIfM/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3rfAh9eFXs0wNVHCkZgXEc5k2MwXsg/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg",
  "rating": 4,
  "relative_time_description": "10 months ago",
  "text": "Not hard to get here. From I-10 w, turn right into Central Ave. Turn right onto 12th st, and park by the first gate on right. You check in there, but then drive thru the 2nd gate. Can\'t stay in the truck while unloading",
  "time": 1528824337
}

...is a problem (see "text" value). Running json_decode on this returns null.

Is this normally a problem? I didn't encounter it while working on my current application until just this morning despite testing using the same location all last week. I can confirm that I've logged the results of the same request and it doesn't contain the escaped single quote, which would be why it was decoding okay at that time.

Eddie
  • 26,593
  • 6
  • 36
  • 58
Ethan C
  • 1,408
  • 1
  • 14
  • 26
  • That is definitely not valid JSON. Good thread if any doubt... https://stackoverflow.com/questions/19176024/how-to-escape-special-characters-in-building-a-json-string/27516892 ignore the accepted answer. – ficuscr Apr 26 '19 at 17:07
  • well, jsonlint and php and phpStorm all seem to agree that the escaping has escaped someone's attention. – YvesLeBorg Apr 26 '19 at 17:07
  • So I guess I'm waiting for Google to fix it? I'll report a bug. – Ethan C Apr 26 '19 at 17:13
  • Sounds like it. Remove PHP from mix and use curl or something from command line. Make sure you still see it. – ficuscr Apr 26 '19 at 17:15
  • @ficuscr good tip, could be something on my end... – Ethan C Apr 26 '19 at 17:24

0 Answers0