jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
913 stars 121 forks source link

How to validate if file is geojson, not normal json? #168

Closed marrog closed 3 years ago

marrog commented 3 years ago

Hi!

How can i use the package to validate if some file is geojson and not normal json (without geometric types included)? What Im currently doing is:

import geojson

def is_geojson(path):
    data = None
    with open(path) as fp:
        try:
            data = geojson.load(fp)
            print(data)
        except Exception as exc:
            print('Exception during geojson validation: ', exc)
        return bool(data)
    return False

In this way every normal json file is recognized as geojson. Please let me know!

Thank you!

marrog commented 3 years ago

Ok, i did it by using another package (If someone's interested: https://pypi.org/project/gjf)