class_docstr: :obj:`JSON` defines API specification for the inputs/outputs of a Service, where either
  inputs will be converted to or outputs will be converted from a JSON representation
  as specified in your API function signature.
  
  A sample service implementation:
  
  .. code-block:: python
     :caption: `service.py`
  
     from __future__ import annotations
  
     import typing
     from typing import TYPE_CHECKING
     from typing import Any
     from typing import Optional
  
     import bentoml
     from bentoml.io import NumpyNdarray
     from bentoml.io import JSON
  
     import numpy as np
     import pandas as pd
     from pydantic import BaseModel
  
     iris_clf_runner = bentoml.sklearn.get("iris_clf_with_feature_names:latest").to_runner()
  
     svc = bentoml.Service("iris_classifier_pydantic", runners=[iris_clf_runner])
  
     class IrisFeatures(BaseModel):
         sepal_len: float
         sepal_width: float
         petal_len: float
         petal_width: float
  
         # Optional field
         request_id: Optional[int]
  
         # Use custom Pydantic config for additional validation options
         class Config:
             extra = 'forbid'
  
  
     input_spec = JSON(pydantic_model=IrisFeatures)
  
     @svc.api(input=input_spec, output=NumpyNdarray())
     def classify(input_data: IrisFeatures) -> NDArray[Any]:
         if input_data.request_id is not None:
             print("Received request ID: ", input_data.request_id)
  
         input_df = pd.DataFrame([input_data.dict(exclude={"request_id"})])
         return iris_clf_runner.run(input_df)
  
  Users then can then serve this service with :code:`bentoml serve`:
  
  .. code-block:: bash
  
      % bentoml serve ./service.py:svc --reload
  
  Users can then send requests to the newly started services with any client:
  
  .. tab-set::
  
      .. tab-item:: Bash
  
          .. code-block:: bash
  
             % curl -X POST -H "content-type: application/json" \
                 --data '{"sepal_len": 6.2, "sepal_width": 3.2, "petal_len": 5.2, "petal_width": 2.2}' \
                 http://127.0.0.1:3000/classify
  
             # [2]%
  
      .. tab-item:: Python
  
          .. code-block:: python
             :caption: `request.py`
  
              import requests
  
              requests.post(
                  "http://0.0.0.0:3000/predict",
                  headers={"content-type": "application/json"},
                  data='{"sepal_len": 6.2, "sepal_width": 3.2, "petal_len": 5.2, "petal_width": 2.2}'
              ).text
  
  Args:
      pydantic_model: Pydantic model schema. When used, inference API callback
                      will receive an instance of the specified ``pydantic_model`` class.
      json_encoder: JSON encoder class. By default BentoML implements a custom JSON encoder that
                    provides additional serialization supports for numpy arrays, pandas dataframes,
                    dataclass-like (`attrs <https://www.attrs.org/en/stable/>`_, dataclass, etc.).
                    If you wish to use a custom encoder, make sure to support the aforementioned object.
  
  Returns:
      :obj:`JSON`: IO Descriptor that represents JSON format.
class_docstr_tok: [":","obj",":","`","JSON","`","defines","API","specification","for","the","inputs\/outputs","of","a","Service",",","where","either","inputs","will","be","converted","to","or","outputs","will","be","converted","from","a","JSON","representation","as","specified","in","your","API","function","signature",".","A","sample","service","implementation",":","..","code-block",":",":","python",":","caption",":","`","service.py","`","from","__future__","import","annotations","import","typing","from","typing","import","TYPE_CHECKING","from","typing","import","Any","from","typing","import","Optional","import","bentoml","from","bentoml.io","import","NumpyNdarray","from","bentoml.io","import","JSON","import","numpy","as","np","import","pandas","as","pd","from","pydantic","import","BaseModel","iris_clf_runner","=","bentoml.sklearn.get","(","``","iris_clf_with_feature_names",":","latest","''",")",".to_runner","(",")","svc","=","bentoml.Service","(","``","iris_classifier_pydantic","''",",","runners=","[","iris_clf_runner","]",")","class","IrisFeatures","(","BaseModel",")",":","sepal_len",":","float","sepal_width",":","float","petal_len",":","float","petal_width",":","float","#","Optional","field","request_id",":","Optional","[","int","]","#","Use","custom","Pydantic","config","for","additional","validation","options","class","Config",":","extra","=","'forbid'","input_spec","=","JSON","(","pydantic_model=IrisFeatures",")","@","svc.api","(","input=input_spec",",","output=NumpyNdarray","(",")",")","def","classify","(","input_data",":","IrisFeatures",")","-",">","NDArray","[","Any","]",":","if","input_data.request_id","is","not","None",":","print","(","``","Received","request","ID",":","``",",","input_data.request_id",")","input_df","=","pd.DataFrame","(","[","input_data.dict","(","exclude=","{","``","request_id","''","}",")","]",")","return","iris_clf_runner.run","(","input_df",")","Users","then","can","then","serve","this","service","with",":","code",":","`","bentoml","serve","`",":","..","code-block",":",":","bash","%","bentoml","serve",".\/service.py",":","svc","--","reload","Users","can","then","send","requests","to","the","newly","started","services","with","any","client",":","..","tab-set",":",":","..","tab-item",":",":","Bash","..","code-block",":",":","bash","%","curl","-X","POST","-H","``","content-type",":","application\/json","''","\\","--","data","'","{","``","sepal_len","''",":","6.2",",","``","sepal_width","''",":","3.2",",","``","petal_len","''",":","5.2",",","``","petal_width","''",":","2.2","}","'","\\","http",":","\/\/127.0.0.1:3000\/classify","#","[","2","]","%","..","tab-item",":",":","Python","..","code-block",":",":","python",":","caption",":","`","request.py","`","import","requests","requests.post","(","``","http",":","\/\/0.0.0.0:3000\/predict","''",",","headers=","{","``","content-type","''",":","``","application\/json","''","}",",","data=","'","{","``","sepal_len","''",":","6.2",",","``","sepal_width","''",":","3.2",",","``","petal_len","''",":","5.2",",","``","petal_width","''",":","2.2","}","'",")",".text","Args",":","pydantic_model",":","Pydantic","model","schema",".","When","used",",","inference","API","callback","will","receive","an","instance","of","the","specified","``","pydantic_model","``","class",".","json_encoder",":","JSON","encoder","class",".","By","default","BentoML","implements","a","custom","JSON","encoder","that","provides","additional","serialization","supports","for","numpy","arrays",",","pandas","dataframes",",","dataclass-like","(","`","attrs","<","https",":","\/\/www.attrs.org\/en\/stable\/",">","`","_",",","dataclass",",","etc.",")",".","If","you","wish","to","use","a","custom","encoder",",","make","sure","to","support","the","aforementioned","object",".","Returns",":",":","obj",":","`","JSON","`",":","IO","Descriptor","that","represents","JSON","format","."]
code: def __init__(
      self,
      *,
      pydantic_model: type[pydantic.BaseModel] | None = None,
      validate_json: bool | None = None,
      json_encoder: type[json.JSONEncoder] = DefaultJsonEncoder,
  ):
      if pydantic_model is not None:
          assert issubclass(
              pydantic_model, pydantic.BaseModel
          ), "'pydantic_model' must be a subclass of 'pydantic.BaseModel'."
  
      self._pydantic_model = pydantic_model
      self._json_encoder = json_encoder
  
      # Remove validate_json in version 1.0.2
      if validate_json is not None:
          logger.warning(
              "'validate_json' option from 'bentoml.io.JSON' has been deprecated. Use a Pydantic model to specify validation options instead."
          )
  
imports: from __future__ import annotations
  import dataclasses
  import json
  import logging
  import typing
  import attr
  from starlette.requests import Request
  from starlette.responses import Response
  from ...exceptions import BadInput
  from ...exceptions import InvalidArgument
  from ..service.openapi import REF_PREFIX
  from ..service.openapi import SUCCESS_DESCRIPTION
  from ..service.openapi.specification import MediaType
  from ..service.openapi.specification import Schema
  from ..types import LazyType
  from ..utils import LazyLoader
  from ..utils import bentoml_cattr
  from ..utils.http import set_cookies
  from ..utils.pkg import pkg_version_info
  from .base import IODescriptor
label_desc: Use image node_id 1 to create a new JSON object from inherited base classes: IODescriptor with example: obj = JSON()