1
1
mirror of https://github.com/wader/fq.git synced 2024-12-03 01:33:02 +03:00
fq/format/bencode/bencode.jq
Mattias Wadman 149cb3f45a interp: Add torepr/0 that converts decode value into what it reptresents
Ex: fq -d msgpack torepr file.msgpack
Willoutput the JSON representation of the msgpack

Make per format *_torepr functions internal
2022-01-12 17:33:58 +01:00

14 lines
365 B
Plaintext

def _bencode_torepr:
def _f:
if .type == "string" then .value | tovalue
elif .type == "integer" then .value | tovalue
elif .type == "list" then .values | map(_f)
elif .type == "dictionary" then
( .pairs
| map({key: (.key | _f), value: (.value | _f)})
| from_entries
)
else error("unknown type \(.type)")
end;
_f;