JSON Format Support for GNDS Data in Fudge
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 36
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
### Question
I have been working with GNDS data and found the support for converting between ENDF and XML formats quite useful. However, I was wondering if there is any native support in Fudge for converting GNDS data to and from JSON format? JSON is a widely-used and convenient format for many applications, especially when integrating with other tools and pipelines.
### Workaround
For now, I am using the following Python code to convert GNDS XML data to JSON format:
```python
import xml.etree.ElementTree as ET
import json
def xml_to_dict(elem):
d = {elem.tag: {} if elem.attrib else None}
children = list(elem)
if children:
dd = {}
for dc in map(xml_to_dict, children):
for k, v in dc.items():
if k in dd:
if not isinstance(dd[k], list):
dd[k] = [dd[k]]
dd[k].append(v)
else:
dd[k] = v
d = {elem.tag: dd}
if elem.attrib:
d[elem.tag].update(('@' + k, v) for k, v in elem.attrib.items())
if elem.text:
text = elem.text.strip()
if children or elem.attrib:
if text:
d[elem.tag]['#text'] = text
else:
d[elem.tag] = text
return d
def convert_gnds(xml_file, json_file):
tree = ET.parse(xml_file)
root = tree.getroot()
gnds_dict = xml_to_dict(root)
with open(json_file, 'w') as f:
json.dump(gnds_dict, f, indent=2)
convert_gnds('gnds_data.xml', 'gnds_data.json')
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no Fudge files or tests; start by locating the existing ENDF/XML conversion entry points and compare their GNDS representations with the supplied Python xml_to_dict and convert_gnds workaround. Done means Fudge can convert GNDS data both to and from JSON with a defined mapping and verified round trips.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- json, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100