I try to display multi line in the map but it return

"Error: Invalid GeoJSON object"

Here is my code

            type:     "POST",
            url:      "server/drawPipe.php",
            data:     {pwa_code : pwa_code},
            success: function(data){

                data = JSON.stringify(data);

                var jsonLayer = L.geoJson().addTo(map_google);


Here is the result that returns from drawPipe.php (I validate this Geojson via http://geojsonlint.com/, the result is correct)


Could anyone suggest me please

  • Try not using JSON.stringify, just take that line out. Commented May 23, 2016 at 7:19
  • still get the same error
    – pich_chaya
    Commented May 23, 2016 at 7:27
  • OK so second idea, do you know why the server returns a MultiLineString when the line has only one part? If you use a LineString (and take out one pair of square brackets), the geometry is still valid. Possibly that's an issue. Commented May 23, 2016 at 7:37
  • Why do you return your coordinates nested on the third level of an array? coordinates[[ [x y],[x y] ]]? Try removing one nesting level.
    – til_b
    Commented May 23, 2016 at 7:37

1 Answer 1


The GeoJSON is valid and renders fine, see http://playground-leaflet.rhcloud.com/kogi/edit?html,output.

However, the use of jquery to fetch it is not. Make sure the request is returning JSON (hint: use dataType: 'json' in your jquery ajax call), and do not stringify the result Ion the contrary, run JSON.parse() if all you've got is a string). If you console.log() the geojson, it should look like a javascript object, not like a string.

Alernatively, ditch jQuery and use the fetch API magical JSON-parsing capabilities.

  • I found the answer!! Only add dataType : 'json' to ajax $.ajax({ type: "POST", url: "server/drawPipe.php", data: {pwa_code : pwa_code}, dataType : 'json', success: function(data){ L.geoJson(data).addTo(map_google); } });
    – pich_chaya
    Commented May 23, 2016 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.