I have custom file format that I use for my program in Python. It stores logic gates in human readable form.
[output-0(
or-0(
and-0(
not-0(
input-0()),
not-1(
input-1())),
and-2(
input-0(),
not-1(
input-1())))),
output-1(
or-1(
and-1(
not-0(
input-0()),
input-1()),
and-2(
input-0(),
not-1(
input-1()))))]
And I want to parse it to json, that looks like this:
[
{
"type": "output",
"id": 0,
"i": [
{
"type": "or",
"id": 0,
"i": [
{
"type": "and",
"id": 0,
"i": [
{
"type": "not",
"id": 0,
"i": [
{
"type": "input",
"id": 0,
"i": []
}
]
},
{
"type": "not",
"id": 1,
"i": [
{
"type": "input",
"id": 1,
"i": []
}
]
}
]
},
{
"type": "and",
"id": 2,
"i": [
{
"type": "input",
"id": 0,
"i": []
},
{
"type": "not",
"id": 1,
"i": [
{
"type": "input",
"id": 1,
"i": []
}
]
}
]
}
]
}
]
},
{
"type": "output",
"id": 1,
"i": [
{
"type": "or",
"id": 1,
"i": [
{
"type": "and",
"id": 1,
"i": [
{
"type": "not",
"id": 0,
"i": [
{
"type": "input",
"id": 0,
"i": []
}
]
},
{
"type": "input",
"id": 1,
"i": []
}
]
},
{
"type": "and",
"id": 2,
"i": [
{
"type": "input",
"id": 0,
"i": []
},
{
"type": "not",
"id": 1,
"i": [
{
"type": "input",
"id": 1,
"i": []
}
]
}
]
}
]
}
]
}
]
Or if it is possible to convert it to python dictionary directly without json. All gate types are: and, or, not, buffer, nand, nor, xor, output, input. Thanks for your help.