I want to export filtered data from JSON to a CSV by selecting a couple of fields and applying a where clause. I get empty output when using either the -sql or -where parameters with the -select (field_list) parameter.

Here are two different formulations of the command:

ex 1)

ogr2ogr -f CSV "output.csv" "raw.json" -select "id","name","type" -where 'type="city"

ex 2)

ogr2ogr -f CSV "output.csv" "raw.json" -sql 'select id,name,type from raw where type="city"'

The following query successfully exports desired fields but unfiltered.

ogr2ogr -f CSV "output.csv" "raw.json" -select "d","name","type"


You need single quotes around city, as it is a literal. Double-quotes indicate an identifier.

Try ogr2ogr -f CSV "output.csv" "raw.json" -sql "select id,name,type from raw where type='city'"

See the documentation for more information. https://www.gdal.org/ogr_sql.html#ogr_sql_quot

|improve this answer|||||
  • Check first with ogrinfo what is the real name of the layer that raw.json contains. It is not necessarily "raw". Read the Layer section from gdal.org/drv_geojson.html. – user30184 May 3 '19 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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