# Path: pytablereader/_constant.py
# class SourceType:
#     TEXT = "text"
#     FILE = "file"
#     URL = "url"
#     OBJECT = "object"
# 
# Path: pytablereader/_constant.py
# class TableNameTemplate:
#     __FORMAT = "%({:s})s"
#     DEFAULT = __FORMAT.format("default")
#     FILENAME = __FORMAT.format("filename")
#     FORMAT_NAME = __FORMAT.format("format_name")
#     FORMAT_ID = __FORMAT.format("format_id")
#     GLOBAL_ID = __FORMAT.format("global_id")
#     KEY = __FORMAT.format("key")
#     TITLE = __FORMAT.format("title")
#     SHEET = __FORMAT.format("sheet")
# 
# Path: pytablereader/error.py
# class ValidationError(Exception):
#     """
#     Exception raised when data is not properly formatted.
#     """
# 
# Path: pytablereader/formatter.py
# class TableFormatter(LoaderAcceptor, TableFormatterInterface):
#     """
#     The abstract class of |TableData| formatter.
#     """
# 
#     def _validate_source_data(self):
#         if not self._source_data:
#             raise DataError("source data is empty")
# 
#     def __init__(self, source_data):
#         self._source_data = source_data
# 
#         self._validate_source_data()
# 
#     def _extract_type_hints(self, headers=None):
#         if self._loader.type_hints:
#             return self._loader.type_hints
# 
#         if not self._loader.type_hint_rules or not headers:
#             return []
# 
#         type_hints = []
#         for header in headers:
#             for regexp, type_hint in self._loader.type_hint_rules.items():
#                 if regexp.search(header):
#                     type_hints.append(type_hint)
#                     break
#             else:
#                 type_hints.append(None)
# 
#         logger.debug(
#             dedent(
#                 """\
#                 extracted type hints:
#                 {}
#                 """
#             ).format(
#                 json.dumps(
#                     OrderedDict(
#                         {header: str(type_hint) for header, type_hint in zip(headers, type_hints)}
#                     ),
#                     indent=4,
#                 )
#             )
#         )
# 
#         return type_hints


import abc
import jsonschema
from tabledata import TableData
from .._constant import SourceType
from .._constant import TableNameTemplate as tnt
from ..error import ValidationError
from ..formatter import TableFormatter
    def _schema(self):
        return {
            "type": "object",
            "additionalProperties": {
                "type": "object",
                "additionalProperties": self._VALUE_TYPE_SCHEMA,
            },
        }

    def to_table_data(self):
        """
        :raises ValueError:
        :raises pytablereader.error.ValidationError:
        """

        self._validate_source_data()

        for table_key, json_records in self._buffer.items():
            self._loader.inc_table_count()
            self._table_key = table_key

            yield TableData(
                self._make_table_name(),
                ["key", "value"],
                [record for record in json_records.items()],
                dp_extractor=self._loader.dp_extractor,
                type_hints=self._extract_type_hints(),
            )



# Path: pytablereader/_constant.py
# class SourceType:
#     TEXT = "text"
#     FILE = "file"
#     URL = "url"
#     OBJECT = "object"
# 
# Path: pytablereader/_constant.py
# class TableNameTemplate:
#     __FORMAT = "%({:s})s"
#     DEFAULT = __FORMAT.format("default")
#     FILENAME = __FORMAT.format("filename")
#     FORMAT_NAME = __FORMAT.format("format_name")
#     FORMAT_ID = __FORMAT.format("format_id")
#     GLOBAL_ID = __FORMAT.format("global_id")
#     KEY = __FORMAT.format("key")
#     TITLE = __FORMAT.format("title")
#     SHEET = __FORMAT.format("sheet")
# 
# Path: pytablereader/error.py
# class ValidationError(Exception):
#     """
#     Exception raised when data is not properly formatted.
#     """
# 
# Path: pytablereader/formatter.py
# class TableFormatter(LoaderAcceptor, TableFormatterInterface):
#     """
#     The abstract class of |TableData| formatter.
#     """
# 
#     def _validate_source_data(self):
#         if not self._source_data:
#             raise DataError("source data is empty")
# 
#     def __init__(self, source_data):
#         self._source_data = source_data
# 
#         self._validate_source_data()
# 
#     def _extract_type_hints(self, headers=None):
#         if self._loader.type_hints:
#             return self._loader.type_hints
# 
#         if not self._loader.type_hint_rules or not headers:
#             return []
# 
#         type_hints = []
#         for header in headers:
#             for regexp, type_hint in self._loader.type_hint_rules.items():
#                 if regexp.search(header):
#                     type_hints.append(type_hint)
#                     break
#             else:
#                 type_hints.append(None)
# 
#         logger.debug(
#             dedent(
#                 """\
#                 extracted type hints:
#                 {}
#                 """
#             ).format(
#                 json.dumps(
#                     OrderedDict(
#                         {header: str(type_hint) for header, type_hint in zip(headers, type_hints)}
#                     ),
#                     indent=4,
#                 )
#             )
#         )
# 
#         return type_hints


# Path: pytablereader/json/formatter.py
import abc
import jsonschema
from tabledata import TableData
from .._constant import SourceType
from .._constant import TableNameTemplate as tnt
from ..error import ValidationError
from ..formatter import TableFormatter

    def _schema(self):
        return {
            "type": "object",
            "additionalProperties": {
                "type": "object",
                "additionalProperties": self._VALUE_TYPE_SCHEMA,
            },
        }

    def to_table_data(self):
        """
        :raises ValueError:
        :raises pytablereader.error.ValidationError:
        """

        self._validate_source_data()

        for table_key, json_records in self._buffer.items():
            self._loader.inc_table_count()
            self._table_key = table_key

            yield TableData(
                self._make_table_name(),
                ["key", "value"],
                [record for record in json_records.items()],
                dp_extractor=self._loader.dp_extractor,
                type_hints=self._extract_type_hints(),
            )



class JsonTableFormatter(TableFormatter):