-
Notifications
You must be signed in to change notification settings - Fork 94
Open
Description
Are there any plans to improve the module loading process? Currently nested modules don't seem to work how I'd like:
~/.jq-test/env.jq
:
module {
name: "env",
description: "Define common environment variables for ease-of-use"
};
def foo: env.FOO | @json;
~/.jq-test/prelude.jq
:
module {
name: "prelude",
description: "Import global functions and modules"
};
import "env" as e;
test-script.sh
:
#!/bin/bash
jq_bin="$1"
export FOO=42
echo "jq_bin: ${jq_bin}"
${jq_bin} -r -n '"direct: \(env.FOO | @json)"'
${jq_bin} -r -n -L ~/.jq-test 'include "env"; "include: \(foo)"'
${jq_bin} -r -n -L ~/.jq-test 'import "env" as e; "import: \(e::foo)"'
${jq_bin} -r -n -L ~/.jq-test 'include "prelude"; "prelude: \(e::foo)"'
$ ./test-script.sh gojq
jq_bin: gojq
direct: "42"
include: "42"
import: "42"
prelude: "42"
$ ./test-script.sh jq
jq_bin: jq
direct: "42"
include: "42"
import: "42"
jq: error: e::foo/0 is not defined at <top-level>, line 1:
include "prelude"; "prelude: \(e::foo)"
jq: 1 compile error
$ ./test-script.sh jaq
jq_bin: jaq
direct: "42"
include: "42"
import: "42"
Error: undefined module
╭─[<inline>]
│
1 │ include "prelude"; "prelude: \(e::foo)"
┆ ┬
┆ │
┆ ╰──────── undefined module
──╯
I understand if you want to go only as far as what jq
is capable of, but I consider gojq
as the more useful implementation in this case.
Or maybe I'm just holding it wrong. In any case, I'd like to hear your thoughts.
$ jaq --version
jaq 2.0.0
$ gojq --version
gojq 0.12.17 (rev: HEAD/go1.23.2)
$ jq --version
jq-1.7.1
Metadata
Metadata
Assignees
Labels
No labels