Giter VIP home page Giter VIP logo

gofx's Introduction

gofx Build Status

fx-like command-line JSON processing tool. This is implementation of some functionality of fx tool.

Features

  • Don't need to learn new syntax
  • Written in Go
  • Formatting and highlighting

Differences

  • Only ES5 (no arrow functions, no spread)
  • Small binary size
  • Can't use npm packages

Install

$ go get github.com/antonmedv/gofx

Or download precompiled binary from releases page.

Usage

Pipe into gofx any JSON and JS code for reducing it.

$ gofx [code ...]

Pretty print JSON without passing any arguments:

$ echo '{"key":"value"}' | gofx
{
    "key": "value"
}

This Binding

You can get access to JSON by this keyword:

$ echo '{"foo": [{"bar": "value"}]}' | gofx 'this.foo[0].bar'
value

Dot

It is possible to omit this keyword:

$ echo '{"foo": [{"bar": "value"}]}' | gofx .foo[0].bar
value

Chain

You can pass any number of code blocks for reducing JSON:

$ echo '{"foo": [{"bar": "value"}]}' | gofx 'this.foo' 'this[0]' 'this.bar'
value

Formatting

If you need something different then JSON (for example arguments for xargs) do not return anything from reducer. undefined value printed into stderr by default.

$ echo '[]' | gofx 'void 0'
undefined
$ echo '[1,2,3]' | gofx 'this.forEach(function (x) { console.log(x) })' 2>/dev/null | xargs echo
1 2 3

Modifying

To modify object use command separated by comma , and return this as the end.

$ echo '{"a": 2}' | gofx 'this["b"] = Math.pow(this.a, 10), this'
{
  "a": 2,
  "b": 1024
}

Object keys

Get all object keys:

$ echo '{"foo": 1, "bar": 2}' | gofx 'Object.keys(this)'
[
  "foo",
  "bar"
]

By the way, gofx has shortcut for Object.keys(this). Previous example can be rewritten as:

$ echo '{"foo": 1, "bar": 2}' | gofx ?

Related

  • fx โ€“ original fx package
  • ymlx - fx-like YAML cli processor

License

MIT

gofx's People

Contributors

antonmedv avatar mattn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.