get-json-value

CLI that returns a value from a path inside JSON files

Usage no npm install needed!

<script type="module">
  import getJsonValue from 'https://cdn.skypack.dev/get-json-value';
</script>

README

get-json-value

Command Line Tool that returns the value of a key path (some.key.path) in one or multiple JSON files.

Installation

$ npm i -g get-json-value

Usage

By default it looks for JSON files in the current working directory.

$ get-json-value <object.key.path> <file> (optional file name)

Examples

Executed in a directory with the following files and contents:

locales/
|__es.json // {"home": {"greeting": "Hola"}}
|__en.json // {"home": {"greeting": "Hello"}}

It will output:

$ get-json-value home.greeting

es Hola
en Hello

Passing file name (without extension):

$ get-json-value home.greeting es

es Hola

Custom search directory

You can specify a custom search directory, for instance, for usage in npm-scripts, by setting the Node env variable GJV_SEARCH_DIR.

"scripts": {
  "getvalue": "GJV_SEARCH_DIR=./path/to/something npx get-json-value"
}
$ npm run getvalue some.path