Code Monkey home page Code Monkey logo

jsjq's Introduction

jsjq - jq with ECMAScript syntax

npm version Test Status Release Status

it uses eval() to run your code, be warned (code is checked and run using safe-eval)

Usage with npx:

npx jsjq '.data.map(x => x*2)' '{"data": [1, 2, 3]}'
# output: [2, 4, 6]

Normal usage:

npm i -g jsjq 

# from JSON string
jsjq '.data.map(x => x*2)' '{"data": [1, 2, 3]}'

# from JSON file
jsjq '.data.map(x => x*2)' example.json

Pipe usage:

echo '{"data": [1, 2, 3]}' | jsjq '.data.map(x => x*2)' 

Custom object methods (may be overridden by properties with the same name):

jsjq '.data.listKeys()' '{ "data": {"a": 1, "b": 2, "c": 3} }'
# output: [ 'a', 'b', 'c' ]

jsjq '.data.listValues()' '{ "data": {"a": 1, "b": 2, "c": 3} }'
# output: [ 1, 2, 3 ]

jsjq '.data.listEntries()' '{ "data": {"a": 1, "b": 2, "c": 3} }'
# output: [ [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ] ]

jsjq '.data.stringify()' '{ "data": {"a": 1, "b": 2, "c": 3} }'
# output: '{"a":1,"b":2,"c":3}'

# override:
jsjq '.data.stringify()' '{ "stringify": 123 }'
# will throw an error

Custom array methods:

jsjq '.data.compact()' '{ "data": [1, 2, 2, 3] }'
# output: [ 1, 2, 3 ]

jsjq '.data.stringify()' '{ "data": [1, 2, 2, 3] }'
# output '[1,2,2,3]'

Options:

  • -c, --compact-output compact instead of pretty-printed output;
  • -r, --raw-output output strings without escapes and quotes;
  • -i, --interactive run jsjq in interactive mode (experimental)
  • -t, --type print the type of the value instead of the value itself;
  • -v, --version show the version;
  • -h, --help show the help;

Code check:

jsjq '.data; process.exit(1)' '{}'
# will throw an error

jsjq's People

Contributors

twoojoo avatar

Watchers

 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.