    def _from_sample(self, sample: JSONType) -> JSONType:
        """
        Create a :class:`~bentoml._internal.io_descriptors.json.JSON` IO Descriptor from given inputs.

        Args:
            sample: A JSON-like datatype, which can be either dict, str, list.
                    ``sample`` will also accepting a Pydantic model.

                    .. code-block:: python

                        from pydantic import BaseModel

                        class IrisFeatures(BaseModel):
                            sepal_len: float
                            sepal_width: float
                            petal_len: float
                            petal_width: float

                        input_spec = JSON.from_sample(
                            IrisFeatures(sepal_len=1.0, sepal_width=2.0, petal_len=3.0, petal_width=4.0)
                        )

                        @svc.api(input=input_spec, output=NumpyNdarray())
                        async def predict(input: NDArray[np.int16]) -> NDArray[Any]:
                            return await runner.async_run(input)
            json_encoder: Optional JSON encoder.

        Returns:
            :class:`~bentoml._internal.io_descriptors.json.JSON`: IODescriptor from given users inputs.

        Example:

        .. code-block:: python
           :caption: `service.py`

           from __future__ import annotations

           import bentoml
           from typing import Any
           from bentoml.io import JSON

           input_spec = JSON.from_sample({"Hello": "World", "foo": "bar"})
           @svc.api(input=input_spec, output=JSON())
           async def predict(input: dict[str, Any]) -> dict[str, Any]:
               return await runner.async_run(input)

        Raises:
            :class:`BadInput`: Given sample is not a valid JSON string, bytes, or supported nest types.
        """
        if LazyType["pydantic.BaseModel"]("pydantic.BaseModel").isinstance(sample):
            self._pydantic_model = sample.__class__
        elif isinstance(sample, str):
            try:
                sample = json.loads(sample)
            except json.JSONDecodeError as e:
                raise BadInput(
                    f"Unable to parse JSON string. Please make sure the input is a valid JSON string: {e}"
                ) from None
        elif isinstance(sample, bytes):
            try:
                sample = json.loads(sample.decode())
            except json.JSONDecodeError as e:
                raise BadInput(
                    f"Unable to parse JSON bytes. Please make sure the input is a valid JSON bytes: {e}"
                ) from None
        elif not isinstance(sample, (dict, list)):
            raise BadInput(
                f"Unable to infer JSON type from sample: {sample}. Please make sure the input is a valid JSON object."
            )
        return sample
Create a :class:`~bentoml._internal.io_descriptors.json.JSON` IO Descriptor from given inputs.

Args:
sample: A JSON-like datatype, which can be either dict, str, list.
``sample`` will also accepting a Pydantic model.

.. code-block:: python

from pydantic import BaseModel

class IrisFeatures(BaseModel):
sepal_len: float
sepal_width: float
petal_len: float
petal_width: float

input_spec = JSON.from_sample(
IrisFeatures(sepal_len=1.0, sepal_width=2.0, petal_len=3.0, petal_width=4.0)
)

@svc.api(input=input_spec, output=NumpyNdarray())
async def predict(input: NDArray[np.int16]) -> NDArray[Any]:
return await runner.async_run(input)
json_encoder: Optional JSON encoder.

Returns:
:class:`~bentoml._internal.io_descriptors.json.JSON`: IODescriptor from given users inputs.

Example:

.. code-block:: python
:caption: `service.py`

from __future__ import annotations

import bentoml
from typing import Any
from bentoml.io import JSON

input_spec = JSON.from_sample({"Hello": "World", "foo": "bar"})
@svc.api(input=input_spec, output=JSON())
async def predict(input: dict[str, Any]) -> dict[str, Any]:
return await runner.async_run(input)

Raises:
:class:`BadInput`: Given sample is not a valid JSON string, bytes, or supported nest types.
src/bentoml/_internal/io_descriptors/json.py