Skip to content

Json file

JsonFileConf

Bases: BaseModel

JSON config model.

Parameters:

Name Type Description Default
filename str

Term to use for the JSON file name.

'$id'
dirpath str

Root directory for JSON files.

required
Source code in stac_generator/plugins/outputs/json_file.py
15
16
17
18
19
20
21
22
23
24
class JsonFileConf(BaseModel):
    """JSON config model."""

    filename: str = Field(
        default="$id",
        description="Term to use for the JSON file name.",
    )
    dirpath: str = Field(
        description="Root directory for JSON files.",
    )

JsonFileOutput

Bases: Output

Output to a JSON file.

Plugin name: json_out

Example Configuration

.. code-block:: yaml

- name: json_out
  conf:
    dirpath: location_to_destination_file
    filename_term: item_id
Source code in stac_generator/plugins/outputs/json_file.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class JsonFileOutput(Output):
    """
    Output to a JSON file.

    **Plugin name:** ``json_out``

    Example Configuration:
        .. code-block:: yaml

            - name: json_out
              conf:
                dirpath: location_to_destination_file
                filename_term: item_id
    """

    config_class = JsonFileConf

    def export(self, data: dict, **kwargs) -> None:
        filename = f"{data[self.conf.filename].strip('/').replace('/', '.')}.json"
        filepath = os.path.join(self.conf.dirpath, filename)

        with open(filepath, "w+", encoding="utf-8") as file:
            json.dump(data, file, indent=4)