diff --git a/setup.py b/setup.py index 38a43e4..1e9ec2f 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ def read(filename): setup( name="py-xbrl", - version="2.2.12", + version="2.2.13", url="https://github.com/manusimidt/xbrl_parser", license='GNU General Public License v3 (GPLv3)', author="Manuel Schmidt", diff --git a/xbrl/__init__.py b/xbrl/__init__.py index 130bcb7..cd8a8bc 100644 --- a/xbrl/__init__.py +++ b/xbrl/__init__.py @@ -76,7 +76,7 @@ class ContextParseException(InstanceParseException): pass -__version__ = '2.2.12' +__version__ = '2.2.13' __author__ = 'Manuel Schmidt ' __all__ = [ XbrlParseException, 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