protected function createJsonResponse(array $data, array $config)
    {
        if (! \is_null($uses = $config['uses'] ?? null)) {
            $data = $data[$uses] ?? [];
        }

        if ($data instanceof Arrayable) {
            $data = $data->toArray();
        }

        $data = \array_map([$this, 'transformToArray'], $data);

        return function () use ($data, $config) {
            return \json_encode($data, $config['encoding'] ?? 0);
        };
    }