Serialize/deserialize to json

master
Micke Nordin 3 years ago
parent d2952ffab1
commit 8e19d33343
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257

@ -74,6 +74,27 @@ class NagObject:
wrap(dir[1], ws_base).strip().strip('\\\n').strip())
return string + '}\n'
def from_object(self, object: dict) -> None:
self.m_type.value = object['type']
self.m_config_file = object['config_file']
self.m_directives = object['directives']
self.m_line_no = object['line_number']
def to_object(self) -> dict:
object = {
'type': self.m_type.value,
'config_file': self.m_config_file,
'directives': self.m_directives,
'line_number': self.m_line_no
}
return object
def from_json(self, string: str) -> None:
self.from_object(json.loads(string))
def to_json(self) -> str:
return json.dumps(self.to_object)
def get_type(self) -> NagObjectType:
return self.m_type

@ -32,6 +32,8 @@ class NagParse:
for object in self.m_objects:
string += str(object) + "\n"
return string
def to_json(self):
return json.dumps([x.to_object() for x in self.m_objects])
def parse_config(self,config_file: str) -> list[NagObject]:
state = ParserState.DEFINE

Loading…
Cancel
Save