code: def extent_to_json(ext_obj):
      """Convert bounds to a shapely geojson like spatial object.
  
      This format is what shapely uses. The output object can be used
      to crop a raster image.
  
      Parameters
      ----------
      ext_obj: list or geopandas geodataframe
          If provided with a geopandas geodataframe, the extent
          will be generated from that. Otherwise, extent values
          should be in the order: minx, miny, maxx, maxy.
  
      Return
      ------
      extent_json: A GeoJSON style dictionary of corner coordinates
      for the extent
          A GeoJSON style dictionary of corner coordinates representing
          the spatial extent of the provided spatial object.
  
      Example
      -------
      >>> import geopandas as gpd
      >>> import earthpy.spatial as es
      >>> from earthpy.io import path_to_example
      >>> rmnp = gpd.read_file(path_to_example('rmnp.shp'))
      >>> es.extent_to_json(rmnp)
      {'type': 'Polygon', 'coordinates': (((-105.4935937, 40.1580827), ...),)}
      """
  
      if type(ext_obj) == gpd.geodataframe.GeoDataFrame:
          extent_json = mapping(box(*ext_obj.total_bounds))
      elif type(ext_obj) == list:
          assert ext_obj[0] <= ext_obj[2], "xmin must be <= xmax"
          assert ext_obj[1] <= ext_obj[3], "ymin must be <= ymax"
          extent_json = mapping(box(*ext_obj))
      else:
          raise ValueError(
              "Please provide a GeoDataFrame or a list of values."
          )
  
      return extent_json
  
file_path: earthpy/earthpy/spatial.py
imports: import os
  import sys
  import contextlib
  import warnings
  import numpy
  from shapely.geometry import mapping, box
  import geopandas
  import rasterio
  from rasterio.mask import mask
label_desc: Use image node_id 1 for calling a global function with example usage: extent_to_json(ext_obj) and returns: extent_json