Skip to content
/ rsl Public

reserialise: lossy but versatile conversion between data serialisation formats

License

Notifications You must be signed in to change notification settings

sentriz/rsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rsl

reserialise: lossy but versatile conversion between data serialisation formats


installation

    $ go install go.senan.xyz/rsl@latest

usage

command line
    $ rsl <src format> <dest format>
available formats
  • csv
  • csv-ph (csv with generated pseudo-header)
  • tsv
  • tsv-ph (tsv with generated pseudo-header)
  • ini
  • js (javascript objects, decode only)
  • json
  • toml
  • xml (lossy support for arbitrary objects)
  • xml-std (lossless but limited)
  • yaml

examples

    $ 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
    [{"addr":"dublin","name":"jim"},{"addr":"space","name":"miguel"}]
    $ rsl json toml <example.json
    [[result]]
      addr = "dublin"
      name = "jim"

    [[result]]
      addr = "space"
      name = "miguel"
    $ rsl json yaml <example.json
    - addr: dublin
      name: jim
    - addr: space
      name: miguel
    $ 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": [
          {
            "#text": "Volvo",
            "@value": "volvo"
          },
          {
            "#text": "Saab",
            "@value": "saab"
          },
          {
            "#text": "Opel",
            "@value": "opel"
          },
          {
            "#text": "Audi",
            "@value": "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

About

reserialise: lossy but versatile conversion between data serialisation formats

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages