The leading @ in the JSON output (e.g., "@id", "@name") is a convention used by xq (and some other XML-to-JSON converters) to represent XML attributes in the JSON output. This is because XML attributes (like id and name in your example) are distinct from XML elements, and the @ prefix helps distinguish them in the JSON structure.
@ Prefixxq with --no-xml-attributesIf your version of xq supports it, you can use the --no-xml-attributes flag to omit the @ prefix for attributes. Try:
bashxq-python --no-xml-attributes . licenses.xml
If this flag is not available, proceed to the next options.
jqUse jq to rename the keys and remove the @ prefix. For example:
bashxq-python . licenses.xml | jq 'walk(if type == "object" then with_entries(.key |= sub("@"; "")) else . end)'
Explanation:
walk recursively traverses the JSON structure.with_entries(.key |= sub("@"; "")) removes the @ prefix from all keys.If you need more control, write a small script (e.g., in Python) to process the JSON and strip the @ prefix from keys. Example:
pythonimport json import sys def remove_at_prefix(obj): if isinstance(obj, dict): return {k.lstrip("@"): remove_at_prefix(v) for k, v in obj.items()} elif isinstance(obj, list): return [remove_at_prefix(item) for item in obj] else: return obj data = json.load(sys.stdin) print(json.dumps(remove_at_prefix(data), indent=2))
Save this as remove_at.py and run:
bashxq-python . licenses.xml | python3 remove_at.py
The output will look like this:
json{ "licenses": { "license": [ { "id": "a", "name": "alpha" }, { "id": "b", "name": "beta" } ] } }
Vibe can make mistakes. Check answers. Learn more