aboutsummaryrefslogtreecommitdiffstats
path: root/config_file/parsers/json_parser.py
blob: 58924b4d4f8de9cacb6ccd6c0945475cea999531 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import json
from typing import Type

from .base_parser import BaseParser


class JsonParser(BaseParser):
    def __init__(self, file_contents: str):
        super().__init__(file_contents)

    @property
    def decode_error(self) -> Type[Exception]:
        return json.decoder.JSONDecodeError

    def loads(self, contents: str) -> dict:
        return json.loads(contents)

    def dumps(self, loaded_contents: dict) -> str:
        return json.dumps(loaded_contents, indent=4)