code: public static int[] getDimensions( JSONArray jsonArray ) {
        // short circuit for empty arrays
        if( jsonArray == null || jsonArray.isEmpty() ){
           return new int[] { 0 };
        }
  
        List dims = new ArrayList();
        processArrayDimensions( jsonArray, dims, 0 );
        int[] dimensions = new int[dims.size()];
        int j = 0;
        for( Iterator i = dims.iterator(); i.hasNext(); ){
           dimensions[j++] = ((Integer) i.next()).intValue();
        }
        return dimensions;
     }
docs: Returns the number of dimensions suited for a java array.