All Projects → chrisdone → Jl

chrisdone / Jl

Licence: other
Functional sed for JSON

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to Jl

Commandtrayhost
A command line program monitor systray for Windows
Stars: ✭ 303 (-32.52%)
Mutual labels:  command-line-tool, command-line, json
Fblog
Small command-line JSON Log viewer
Stars: ✭ 137 (-69.49%)
Mutual labels:  command-line-tool, command-line, json
Json 2 Kotlin
Convert JSON to Kotlin Data Classes
Stars: ✭ 148 (-67.04%)
Mutual labels:  command-line-tool, command-line, json
Jsonui
jsonui is an interactive JSON explorer on your command line
Stars: ✭ 583 (+29.84%)
Mutual labels:  command-line-tool, command-line, json
Tq
Perform a lookup by CSS selector on an HTML input
Stars: ✭ 193 (-57.02%)
Mutual labels:  command-line-tool, command-line, json
Starcli
✨ Browse GitHub trending projects from your command line
Stars: ✭ 269 (-40.09%)
Mutual labels:  command-line-tool, command-line
Urs
Universal Reddit Scraper - A comprehensive Reddit scraping command-line tool written in Python.
Stars: ✭ 275 (-38.75%)
Mutual labels:  command-line, json
Define
A command-line dictionary (thesaurus) app, with access to multiple sources, written in Go.
Stars: ✭ 298 (-33.63%)
Mutual labels:  command-line-tool, command-line
Jwt Cli
A super fast CLI tool to decode and encode JWTs built in Rust
Stars: ✭ 336 (-25.17%)
Mutual labels:  command-line-tool, json
Xidel
Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
Stars: ✭ 335 (-25.39%)
Mutual labels:  command-line, json
Tsukae
🧑‍💻📊 Show off your most used shell commands
Stars: ✭ 345 (-23.16%)
Mutual labels:  command-line-tool, command-line
Ff
Find files (ff) by name, fast!
Stars: ✭ 257 (-42.76%)
Mutual labels:  command-line-tool, command-line
Menyoki
Screen{shot,cast} and perform ImageOps on the command line 🌱 🏞️
Stars: ✭ 255 (-43.21%)
Mutual labels:  command-line-tool, command-line
Theme.sh
A script which lets you set your $terminal theme.
Stars: ✭ 290 (-35.41%)
Mutual labels:  command-line-tool, command-line
Websocat
Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
Stars: ✭ 3,477 (+674.39%)
Mutual labels:  command-line-tool, command-line
Gitlab Cli
Create a merge request from command line in gitlab
Stars: ✭ 224 (-50.11%)
Mutual labels:  command-line-tool, command-line
Sendmidi
Multi-platform command-line tool to send out MIDI messages
Stars: ✭ 411 (-8.46%)
Mutual labels:  command-line-tool, command-line
Jmxterm
Interactive command line JMX client
Stars: ✭ 389 (-13.36%)
Mutual labels:  command-line-tool, command-line
Azure Devops Cli Extension
Azure DevOps Extension for Azure CLI
Stars: ✭ 420 (-6.46%)
Mutual labels:  command-line-tool, command-line
Jtc
JSON processing utility
Stars: ✭ 425 (-5.35%)
Mutual labels:  command-line, json

jl Build Status

jl ("JSON lambda") is a tiny functional language for querying and manipulating JSON.

Example:

$ jl 'map $ \o -> { sha: o.sha, ps: map _.sha o.parents }' x.json
[{"sha":"7b81a836c31500e685d043729259affa8b670a87","ps":["c538237f4e4c381d35f1c15497c...

Installing

Binary releases for Linux and OS X are available here.

Builds on Windows (see AppVeyor status), haven't added Windows binaries to the releases yet.

Installing from source:

  1. Get stack
  2. Run stack install in the repository directory.
  3. Add ~/.local/bin/ to your PATH.

Core syntax

Literals:

123, 4.5, -6, "hi", null, true, false

Lambdas:

\x -> y

Function application

get "f" o

Arithmetic:

x * (4 + 3)

Objects:

{foo: 123, bar: 34.3, "a:b": "hi"}

Arrays:

[1, 4 * 5, id 5]

Conditionals:

if x then y else z

Short-hand for fields:

o.f  is sugar for         get "f" o
_.f  is sugar for  (\o -> get "f" o)

For arrays:

_[0] is sugar for   (\o -> get 0 o)

Or objects:

_[k]     is sugar for   (\o -> get k o)
_["foo"] is sugar for   (\o -> get "foo" o)

Function composition:

a | b | c is sugar for `\x -> c (b (a x))`

Mini tutorial

You do everything with usual functional programming functions.

Returning the same thing, aka identity. That's normal in functional programming:

jl 'id'

A sequence of JSON strings will be read in and processed individually:

E.g.

$ cat x.json | jl id
{"a":1}
{"a":2}
{"a":3}
{"a":4}

If you want to read the input in as an array, use --array:

$ cat x.json | jl --array 'map _.a'
[1,2,3,4]

After processing, sometimes you want to print each element of the array out line by line, for that use --lines:

$ cat x.json | jl --array --lines 'map _.a'
1
2
3
4

Taking the first element of something, using syntax that looks like regular array access. The _ is a short-hand so that you don't need a lambda:

jl '_[0]'

If you want to get what keys are available, you can run:

jl 'map keys | _[0]'
["sha","committer","url","comments_url","parents","author","html_url","commit"]

Taking the first element and then creating a record of some parts of it:

jl '_[0] | \o -> {msg: o.commit.message, n: o.commit.committer.name}'

Note the use of | to compose functions. Just like in the shell.

Applying a function to all elements in an array:

jl 'map _.commit.committer.name'

Note how you can nest property access easily.

Applying something more detailed, by constructing a record of our own

jl 'map $ \o -> {msg: o.commit.message, n: o.commit.committer.name}'

You can use $ to avoid using parentheses on the right. That's a trick from Haskell.

Applying functions to nested data structures:

jl '_[0] | \o -> {msg: o.commit.message, n: o.commit.committer.name, ps: map _.html_url o.parents }'

Notice the ps property comes by taking the html_url of all the parents.

Filtering is easy, simply write a function that returns true:

jl 'map (\o -> { sha: o.sha, ps: map _.sha o.parents }) | filter (\o -> length o.ps > 1)'

If you want to make an object with arbitrary keys that come at runtime, use set:

$ echo '"hello"' | jl '\x -> set x 123 {}'
{"hello":123}

This sets the key x in the empty object {} to "hello" with the value 123. You can use set repeatedly to construct more keys.

If you want to construct an object from a list of key/values, you can use fold:

$ echo '[{"k":"foo","v":123},{"k":"bar","v":456}]' | jl 'fold (\acc o -> set o.k o.v acc) {}'
{"foo":123,"bar":456}

Available functions

Record access

get :: JSON  JSON  JSON

Get the value at k from the object

set :: JSON  JSON  JSON  JSON

Set the value k to v in object

modify :: JSON  (JSON  JSON)  JSON  JSON

Modify the object at k with function f

keys :: JSON  JSON

Get all keys of the object

elems :: JSON  JSON

Get all elements of the object

Sequences

map :: (JSON  JSON)  JSON  JSON

Apply a function to every element in the sequence

filter :: (JSON  JSON)  JSON  JSON

Keep only items from the sequence for which p returns true

takeWhile :: (JSON  JSON)  JSON  JSON

Take elements from a sequence while given predicate is true

empty :: JSON  JSON

Is a sequence empty?

length :: JSON  JSON

Get the length of a sequence

reverse :: JSON  JSON

Reverse a sequence

drop :: JSON  JSON  JSON

Drop n items from the sequence

elem :: JSON  JSON  JSON

Is x an element of y?

concat :: JSON  JSON

Concatenate a list of sequences into one sequence

zipWith :: (JSON  JSON  JSON)  JSON  JSON  JSON

Zip two lists calling with each element to f x y

take :: JSON  JSON  JSON

Take n items from sequence

fold :: (JSON  JSON  JSON)  JSON  JSON  JSON

Fold over a structure with a state.

dropWhile :: (JSON  JSON)  JSON  JSON

Drop elements from a sequence while a predicate is true

any :: (JSON  JSON)  JSON  JSON

Does p return true for any of the elements?

all :: (JSON  JSON)  JSON  JSON

Does p return true for all of the elements?

nub :: JSON  JSON

Return the sequence with no duplicates; the nub of it

sort :: JSON  JSON

Return the sequence sorted

append :: JSON  JSON  JSON

Append the members of the second sequence to the first sequence

sum :: JSON  JSON

Get the sum of a sequence

product :: JSON  JSON

Get the product of a sequence

minimum :: JSON  JSON

Get the minimum of a sequence

maximum :: JSON  JSON

Get the maximum of a sequence

Strings

words :: JSON  JSON

Split the string into a list of words

unwords :: JSON  JSON

Join the list of strings into a string separated by spaces

lines :: JSON  JSON

Split the string into a list of lines

unlines :: JSON  JSON

Join the list of strings into a string separated by lines and terminated by a new line

Predicate operators

/= :: JSON  JSON  JSON

a /= b

= :: JSON  JSON  JSON

a = b

Boolean operators

&& :: JSON  JSON  JSON

a && b

|| :: JSON  JSON  JSON

a || b

not :: JSON  JSON

not b

Numeric operators

> :: JSON  JSON  JSON

a > b

< :: JSON  JSON  JSON

a < b

>= :: JSON  JSON  JSON

a >= b

<= :: JSON  JSON  JSON

a <= b

* :: JSON  JSON  JSON

a * b

+ :: JSON  JSON  JSON

a + b

- :: JSON  JSON  JSON

a - b

/ :: JSON  JSON  JSON

a / b

min :: JSON  JSON  JSON

a min b

max :: JSON  JSON  JSON

a max b

abs :: JSON  JSON

abs b

Function combinators

id :: JSON  JSON

Identity function, returns its input unchanged

compose :: (JSON  JSON)  (JSON  JSON)  JSON  JSON

Compose two functions

flip :: (JSON  JSON  JSON)  JSON  JSON  JSON

Flips the argument order of a function of two or more arguments

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].