reserialise: lossy but versatile conversion between data serialisation formats
$ go install go.senan.xyz/rsl@latest
$ rsl <src format> <dest format>
- csv
- csv-ph (csv with generated pseudo-header)
- tsv
- tsv-ph (tsv with generated pseudo-header)
- html (decode only)
- ini
- js (javascript objects, decode only)
- json
- md
- toml
- xml (lossy support for arbitrary objects, lenient decoding)
- yaml
$ rsl toml csv <some-toml.toml >some-csv.csv $ cat example.json
[
{
"name": "jim",
"addr": "dublin"
},
{
"name": "miguel",
"addr": "space"
}
] $ rsl json json <example.json
[{"name":"jim","addr":"dublin"},{"name":"miguel","addr":"space"}] $ rsl json toml <example.json
[[result]]
addr = "dublin"
name = "jim"
[[result]]
addr = "space"
name = "miguel" $ rsl json yaml <example.json
- name: jim
addr: dublin
- name: miguel
addr: space $ rsl json csv <example.json
name,addr
jim,dublin
miguel,space $ cat example.simple.json
[
[
"jim",
"dublin"
],
[
"miguel",
"space"
]
] # generate pseudo headers if there are none. makes it easy to query with other tools
$ rsl json csv <example.simple.json
a,b
jim,dublin
miguel,space $ cat example.html
<select id="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select> $ rsl xml json <example.html | jq
{
"select": {
"@id": "cars",
"option": [
{
"@value": "volvo",
"#text": "Volvo"
},
{
"@value": "saab",
"#text": "Saab"
},
{
"@value": "opel",
"#text": "Opel"
},
{
"@value": "audi",
"#text": "Audi"
}
]
}
} $ rsl xml json <example.html | jq -r '.select.option | .[] | select(."@value" == "saab") | ."#text"'
Saab $ cat example.csv
year,artist,album
1981,Alan Vega,"Collision Drive"
1991,Underground Resistance,"The Final Frontier"
1999,Dopplereffekt,Gesamtkunstwerk
2002,Dopplereffekt,Myon-Neutrino
2016,Pangaea,"In Drum Play" $ rsl csv json <example.csv | jq -r '.[] | select(.artist == "Dopplereffekt") | .album'
Gesamtkunstwerk
Myon-Neutrino # parse javascript objects
$ node -e 'console.log({colour: "blue", v: Math.random()})' | rsl js yaml
colour: blue
v: 0.7409782831156317