Skip to content

dqft/shell-with-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

JSON objects within shell scripts

These two functions allow you to rely on JSON objects within your shell scripts.

Example

#!/bin/sh

# load functions
source sh-json.sh

# call a function and turn its return as json
funcA() {
	json=$(funcB -first "some value" -second "something else")
	result=$(_get result "$json")

	echo $result # result: congratulations! it works!
}

# turn arguments into json and extract its variables
funcB() {
	json=$(_set "$@")
	key1=$(_get first "$json")
	key2=$(_get second "$json")

	[[ $key1 == "some value" ]] && [[ $key2 == "something else" ]] || return 1
	_set -result "congratulations! it works!"
}

main() {
	funcA
}

main

TODO

  • handle integers and booleans
  • handle arrays
  • any suggestion?

About

Use JSON objects within your shell scripts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages