MyNixOS website logo
Description

json to xlsx converter.

jsonxlsx

Transforms a standard JSON format to a Excel xlsx document.

This project is experimental; jsonxlsx's xlsx output has not been tested with Excel, only with OpenOffice.

Install

You must have a recent version of the Haskell Platform on your system.

A prerequisite is a the xlsx fork at https://github.com/danchoi/xlsx, which must be added to the cabal sandbox before building jsonxlsx. Here are the steps

git clone [email protected]/danchoi/xlsx
git clone [email protected]/danchoi/jsonxlsx
cd jsonxlsx
cabal update
cabal sandbox init
cabal sandbox add-source ../xlsx
cabal install --only-dependencies
cabal build

# Now copy dist/build/jsonxlsx/jsonxlsx to a location on your PATH

Usage

jsonxlsx

Usage: jsonxlsx [-a DELIM] FIELDS OUTFILE [--debug]
  Transform JSON object steam to XLSX. On STDIN provide an input stream of
  newline-separated JSON objects.

Available options:
  -h,--help                Show this help text
  -a DELIM                 Concatentated array elem delimiter. Defaults to
                           comma.
  FIELDS                   JSON keypath expressions
  OUTFILE                  Output file to write to. Use '-' to emit binary xlsx
                           data to STDOUT.
  --debug                  Debug keypaths

Example:

This is the input JSON object stream:

sample.json:

{
  "title": "Terminator 2: Judgement Day",
  "year": 1991,
  "stars": [
    {
      "name": "Arnold Schwarzenegger"
    },
    {
      "name": "Linda Hamilton"
    }
  ],
  "ratings": {
    "imdb": 8.5
  }
}
{
  "title": "Interstellar",
  "year": 2014,
  "stars": [
    {
      "name": "Matthew McConaughey"
    },
    {
      "name": "Anne Hathaway"
    }
  ],
  "ratings": {
    "imdb": 8.9
  }
}

This is the command to turn this stream into an XLSX file:

< sample.json jsonxlsx \
  'title:"Movie Title" year stars.name:"Movie Actors" ratings.imdb:"IMDB Score"' \
  movies.xlsx 

This is the output (movies.xlsx):

screen

See the README for jsontsv to see how to use jq to generate JSON object streams from nested JSON data structures.

Future improvements

The xlsx library that jsonxlsx uses to generate Excel output seems to have ways to control the column widths and other characteristics of the Excel spreadsheet. Contributors are welcome to add ways of controlling these parameters to jsonxlsx.

Related

Metadata

Version

0.1.0.1

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows