public static int validateGeoJson(InputStream is){
  int n=0;
  JsonFactory f=new JsonFactory();
  try {
    JsonParser jp=f.createParser(is);
    JsonToken current=jp.nextToken();
    if (current != JsonToken.START_OBJECT) {
      LOG.error("Root of OTPA GeoJSON should be a JSON object.");
      return -1;
    }
    while (jp.nextToken() != JsonToken.END_OBJECT) {
      String key=jp.getCurrentName();
      current=jp.nextToken();
      if (key.equals("features")) {
        if (current != JsonToken.START_ARRAY) {
          LOG.error("Error: GeoJSON features are not in an array.");
          return -1;
        }
        while (jp.nextToken() != JsonToken.END_ARRAY) {
          n+=1;
          jp.skipChildren();
        }
      }
 else {
        jp.skipChildren();
      }
    }
    if (n == 0)     return -1;
    return n;
  }
 catch (  Exception ex) {
    LOG.error("Exception while validating GeoJSON: {}",ex);
    return -1;
  }
}

public static int validateGeoJson ( InputStream is ) { int n = 0 ; JsonFactory f = new JsonFactory ( ) ; try { JsonParser jp = f . createParser ( is ) ; JsonToken current = jp . nextToken ( ) ; if ( current != JsonToken . START_OBJECT ) { LOG . error ( "Root of OTPA GeoJSON should be a JSON object." ) ; return - 1 ; } while ( jp . nextToken ( ) != JsonToken . END_OBJECT ) { String key = jp . getCurrentName ( ) ; current = jp . nextToken ( ) ; if ( key . equals ( "features" ) ) { if ( current != JsonToken . START_ARRAY ) { LOG . error ( "Error: GeoJSON features are not in an array." ) ; return - 1 ; } while ( jp . nextToken ( ) != JsonToken . END_ARRAY ) { n += 1 ; jp . skipChildren ( ) ; } } else { jp . skipChildren ( ) ; } } if ( n == 0 ) return - 1 ; return n ; } catch ( Exception ex ) { LOG . error ( "Exception while validating GeoJSON: {}" , ex ) ; return - 1 ; } }
examines a json stream to see if it matches the expected otpa format . todo improve the level of detail of validation . many files pass the validation and then crash the load function .
