class_docstr: JSON IO
  
  Example:
  
  .. code-block:: python
  
      import typing as T
      from pydantic import BaseModel
      from towhee import AutoPipes, api_service
      from towhee.serve.io import JSON
  
      service = api_service.APIService(desc="Welcome")
      stn = AutoPipes.pipeline('sentence_embedding')
  
      @service.api(path='/embedding', input_model = JSON(), output_model=JSON())
      def chat(params: T.List[T.Any]):
          return stn(*params).to_list()
  
      class Item(BaseModel):
          url: str
          ids: T.List[int]
  
      @service.api(path='/echo', input_model = JSON(Item), output_model=JSON(Item))
      def echo(item: Item):
          return item
  
      Client Example:
          http:
  
          .. code-block:: python
  
              import requests
              requests.post('http://127.0.0.1:8000/echo', json={'url': 1, 'ids': [1, 2]}).json()
              requests.post('http://127.0.0.1:8000/embedding', json=['hello world']).json()
  
          grpc:
  
          .. code-block:: python
  
              from towhee.serve.grpc.client import Client
              c = Client('0.0.0.0', 8000)
              c('/echo', {'url': 1, 'ids': [1, 2]})
              c('/embedding', ['hello'])
class_docstr_tok: ["JSON","IO","Example",":","..","code-block",":",":","python","import","typing","as","T","from","pydantic","import","BaseModel","from","towhee","import","AutoPipes",",","api_service","from","towhee.serve.io","import","JSON","service","=","api_service.APIService","(","desc=","''","Welcome","''",")","stn","=","AutoPipes.pipeline","(","'sentence_embedding","'",")","@","service.api","(","path='\/embedding","'",",","input_model","=","JSON","(",")",",","output_model=JSON","(",")",")","def","chat","(","params",":","T.List","[","T.Any","]",")",":","return","stn","(","*","params",")",".to_list","(",")","class","Item","(","BaseModel",")",":","url",":","str","ids",":","T.List","[","int","]","@","service.api","(","path='\/echo","'",",","input_model","=","JSON","(","Item",")",",","output_model=JSON","(","Item",")",")","def","echo","(","item",":","Item",")",":","return","item","Client","Example",":","http",":","..","code-block",":",":","python","import","requests","requests.post","(","'http",":","\/\/127.0.0.1:8000\/echo","'",",","json=","{","'url","'",":","1",",","'ids","'",":","[","1",",","2","]","}",")",".json","(",")","requests.post","(","'http",":","\/\/127.0.0.1:8000\/embedding","'",",","json=","[","'hello","world","'","]",")",".json","(",")","grpc",":","..","code-block",":",":","python","from","towhee.serve.grpc.client","import","Client","c","=","Client","(","'","0.0.0.0","'",",","8000",")","c","(","'\/echo","'",",","{","'url","'",":","1",",","'ids","'",":","[","1",",","2","]","}",")","c","(","'\/embedding","'",",","[","'hello","'","]",")"]
code: def __init__(self, model: Optional[BaseModel] = None):
      self._model = model
  
file_path: towhee/towhee/serve/io/json_io.py
imports: import asyncio
  from typing import Optional, Union, Any
  from pydantic import BaseModel
  from .base import IOBase, IOType
  from towhee.utils.serializer import to_json, from_json
label_desc: Use image node_id 1 to create a new JSON object from inherited base classes: IOBase with example: obj = JSON(model)