diff --git a/xbrl/linkbase.py b/xbrl/linkbase.py index d11ed67..931f496 100644 --- a/xbrl/linkbase.py +++ b/xbrl/linkbase.py @@ -1,4 +1,5 @@ import abc +import json import os import xml.etree.ElementTree as ET from abc import ABC @@ -247,6 +248,23 @@ def __init__(self, label: str, label_type: str, language: str, text: str) -> Non # the role of the label i.e: http://www.xbrl.org/2003/role/terseLabel self.label_type: str = label_type + def to_dict(self): + """ + Converts the Label object into a dictionary representation + """ + return { + 'label': self.label, + 'label_type': self.label_type, + 'language': self.language, + 'text': self.text + } + + def to_json(self): + """ + Converts the Label object into a JSON string + """ + return json.dumps(self.to_dict(), indent=4) + def __str__(self) -> str: return self.text diff --git a/xbrl/taxonomy.py b/xbrl/taxonomy.py index 8af967e..010d135 100644 --- a/xbrl/taxonomy.py +++ b/xbrl/taxonomy.py @@ -3,6 +3,7 @@ """ import logging import os +import json import xml.etree.ElementTree as ET from functools import lru_cache from typing import List @@ -480,6 +481,29 @@ def __init__(self, xml_id: str, schema_url: str, name: str) -> None: self.period_type: str or None = None self.balance: str or None = None self.labels: [Label] = [] + + def to_dict(self): + """ + Converts the Concept object into a dictionary representation + """ + return { + 'xml_id': self.xml_id, + 'schema_url': self.schema_url, + 'name': self.name, + 'substitution_group': self.substitution_group, + 'concept_type': self.concept_type, + 'abstract': self.abstract, + 'nillable': self.nillable, + 'period_type': self.period_type, + 'balance': self.balance, + 'labels': [label.to_dict() for label in self.labels] if self.labels else [] # Assuming Label class has to_dict() + } + + def to_json(self): + """ + Converts the Concept object into a JSON string + """ + return json.dumps(self.to_dict(), indent=4) def __str__(self) -> str: return self.name