code: async def apply_json(self, data):
          
          if not isinstance(data, list):
              data = [data]
          result = []
          for entry in data:
              if not isinstance(entry, dict):
                  raise KongError('dictionary required')
              ensure = entry.pop('ensure', None)
              name = entry.pop('name', None)
              routes = entry.pop('routes', [])
              plugins = entry.pop('plugins', [])
              host = entry.pop('host', None)
              if host in LOCAL_HOST:
                  host = local_ip()
              if not name:
                  raise KongError('Service name is required')
              if ensure in REMOVE:
                  if await self.has(name):
                      await self.delete(name)
                  continue
              # backward compatible with config entry
              config = entry.pop('config', None)
              if isinstance(config, dict):
                  entry.update(config)
              if await self.has(name):
                  srv = await self.update(name, host=host, **entry)
              else:
                  srv = await self.create(name=name, host=host, **entry)
              srv.data['routes'] = await srv.routes.apply_json(routes)
              srv.data['plugins'] = await srv.plugins.apply_json(plugins)
              result.append(srv.data)
          return result
docs: Apply a JSON data object for a service