Why are my GeoJSON files being saved without line breaks? Why are they missing the proper formatting? All features in the file are being saved in the same line.

I'm using QGIS 3.6.3.

enter image description here File opened in Emeditor

Here is what I believe is "proper formatting"

enter image description here

  • 2
    What happens if you open your GeoJSON with Notepad++? Or alternatively: what program do you use to view it?
    – MrXsquared
    Commented May 28, 2019 at 20:02
  • 7
    This "proper formatting" is just optional whitespace. Including or excluding it does not affect the validity of your JSON data. Commented May 28, 2019 at 20:19
  • @MrXsquared I just added a screenshot of what it looks like when I open it in Notepad and then Emeditor. The problem is I'm trying to upload the file to MapBox but it's not formatted correctly because all of the features are saved in the same line and MapBox reads that as a single feature. This is a new problem for my geojson files.
    – csft306
    Commented May 28, 2019 at 20:19
  • 1
    @RichardLaw I just added a photo of what I refer to as 'proper formatting'
    – csft306
    Commented May 28, 2019 at 20:23
  • 3
    There are many "pretty print" JSON tools around, here one as an example jsonprettyprint.org
    – user30184
    Commented May 28, 2019 at 20:43

1 Answer 1


The JSON format does not strictly foresee line breaks: a valid JSON files can be just a self-enclosed, single-line string.

It is to be noted however that (from the official ECMA-404 document)

Insignificant whitespace is allowed before or after any token. Whitespace is any sequence of one or more of the following code points: character tabulation (U+0009), line feed (U+000A), carriage return (U+000D), and space (U+0020). Whitespace is not allowed within any token, except that space is allowed in strings.

One can therefore add line breaks (before or after tokens) to improve readability, but they are completely optional, and that is one of the reasons why most programs do not add them to their outputs.

As for importing GeoJSONs into MapBox, they suggest a number of tools:

There are several open source tools for converting other geospatial data formats to GeoJSON. A few favorites are:

  • togeojson, a node package for converting KML and GPX (XML formats).
  • ogr2ogr, the ultimate 40-in-1 vector data conversion tool.
  • geojson.net for creating, converting, and editing GeoJSON.

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.