rsl

command module
v0.0.0-...-0bc5b10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 12 Imported by: 0

README

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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL