Using wp_localize_script to get data from cpt and pass it to maplace-js locations

You don’t need to use json_encode() when using wp_localize_script(). The last argument of wp_localize_script() should be a PHP array. This will be converted to JSON for you.

So to resolve the issue, remove this line:

$location_json = json_encode($location_array);

And change wp_localize_script() to use $location_array:

wp_localize_script('sage/main.js', 'locationJSON', $location_array);

Because $location_array had been double-encoded the locationJSON variable was actually just a text string that looked like JSON. So when the Maplace script tried to access the first element of the array with locationJSON[0] it failed because the locationJSON variable was not actually an Array.