INDEX builtin with input
I'm trying to build an INDEX from a json file which contains a list of flat objects.
If I use the construct
jq 'INDEX(.a + ":" + .b)' < data.json
I get what i want. But if I use
jq 'INDEX(input; .a + ":" + .b) data.json
then I get the error
jq: error (at data.json:<last-line>): break
The reason I need to use the second form is that I will then need to JOIN another input
to the index of the first, and I don't see how to do that from STDIN.
Any ideas how I can get around this?
(Currently running jq-1.6 on MacOS 10.13.6)
Adding input (data.json):
[
{
"a": "a1",
"b": "b1",
"c": "c1",
"d": "d1"
},
{
"a": "a2",
"b": "b2",
"c": "c2",
"d": "d2"
},
{
"a": "a3",
"b": "b3",
"c": "c3",
"d": "d3"
}
]
And expected output
{
"a1:b1": {
"a": "a1",
"b": "b1",
"c": "c1",
"d": "d1"
},
"a2:b2": {
"a": "a2",
"b": "b2",
"c": "c2",
"d": "d2"
},
"a3:b3": {
"a": "a3",
"b": "b3",
"c": "c3",
"d": "d3"
}
}
jq
add a comment |
I'm trying to build an INDEX from a json file which contains a list of flat objects.
If I use the construct
jq 'INDEX(.a + ":" + .b)' < data.json
I get what i want. But if I use
jq 'INDEX(input; .a + ":" + .b) data.json
then I get the error
jq: error (at data.json:<last-line>): break
The reason I need to use the second form is that I will then need to JOIN another input
to the index of the first, and I don't see how to do that from STDIN.
Any ideas how I can get around this?
(Currently running jq-1.6 on MacOS 10.13.6)
Adding input (data.json):
[
{
"a": "a1",
"b": "b1",
"c": "c1",
"d": "d1"
},
{
"a": "a2",
"b": "b2",
"c": "c2",
"d": "d2"
},
{
"a": "a3",
"b": "b3",
"c": "c3",
"d": "d3"
}
]
And expected output
{
"a1:b1": {
"a": "a1",
"b": "b1",
"c": "c1",
"d": "d1"
},
"a2:b2": {
"a": "a2",
"b": "b2",
"c": "c2",
"d": "d2"
},
"a3:b3": {
"a": "a3",
"b": "b3",
"c": "c3",
"d": "d3"
}
}
jq
Please add example input and output to your question.
– oguzismail
Nov 13 '18 at 8:46
1
@oguzismail : examples added
– tyke
Nov 13 '18 at 10:30
add a comment |
I'm trying to build an INDEX from a json file which contains a list of flat objects.
If I use the construct
jq 'INDEX(.a + ":" + .b)' < data.json
I get what i want. But if I use
jq 'INDEX(input; .a + ":" + .b) data.json
then I get the error
jq: error (at data.json:<last-line>): break
The reason I need to use the second form is that I will then need to JOIN another input
to the index of the first, and I don't see how to do that from STDIN.
Any ideas how I can get around this?
(Currently running jq-1.6 on MacOS 10.13.6)
Adding input (data.json):
[
{
"a": "a1",
"b": "b1",
"c": "c1",
"d": "d1"
},
{
"a": "a2",
"b": "b2",
"c": "c2",
"d": "d2"
},
{
"a": "a3",
"b": "b3",
"c": "c3",
"d": "d3"
}
]
And expected output
{
"a1:b1": {
"a": "a1",
"b": "b1",
"c": "c1",
"d": "d1"
},
"a2:b2": {
"a": "a2",
"b": "b2",
"c": "c2",
"d": "d2"
},
"a3:b3": {
"a": "a3",
"b": "b3",
"c": "c3",
"d": "d3"
}
}
jq
I'm trying to build an INDEX from a json file which contains a list of flat objects.
If I use the construct
jq 'INDEX(.a + ":" + .b)' < data.json
I get what i want. But if I use
jq 'INDEX(input; .a + ":" + .b) data.json
then I get the error
jq: error (at data.json:<last-line>): break
The reason I need to use the second form is that I will then need to JOIN another input
to the index of the first, and I don't see how to do that from STDIN.
Any ideas how I can get around this?
(Currently running jq-1.6 on MacOS 10.13.6)
Adding input (data.json):
[
{
"a": "a1",
"b": "b1",
"c": "c1",
"d": "d1"
},
{
"a": "a2",
"b": "b2",
"c": "c2",
"d": "d2"
},
{
"a": "a3",
"b": "b3",
"c": "c3",
"d": "d3"
}
]
And expected output
{
"a1:b1": {
"a": "a1",
"b": "b1",
"c": "c1",
"d": "d1"
},
"a2:b2": {
"a": "a2",
"b": "b2",
"c": "c2",
"d": "d2"
},
"a3:b3": {
"a": "a3",
"b": "b3",
"c": "c3",
"d": "d3"
}
}
jq
jq
edited Nov 13 '18 at 10:16
tyke
asked Nov 13 '18 at 8:44
tyketyke
234
234
Please add example input and output to your question.
– oguzismail
Nov 13 '18 at 8:46
1
@oguzismail : examples added
– tyke
Nov 13 '18 at 10:30
add a comment |
Please add example input and output to your question.
– oguzismail
Nov 13 '18 at 8:46
1
@oguzismail : examples added
– tyke
Nov 13 '18 at 10:30
Please add example input and output to your question.
– oguzismail
Nov 13 '18 at 8:46
Please add example input and output to your question.
– oguzismail
Nov 13 '18 at 8:46
1
1
@oguzismail : examples added
– tyke
Nov 13 '18 at 10:30
@oguzismail : examples added
– tyke
Nov 13 '18 at 10:30
add a comment |
1 Answer
1
active
oldest
votes
The first argument of INDEX/2
should be a stream of the items to be indexed; here, .
is exactly what we want:
INDEX(.; .a + ":" + .b)
You're right. That is EXACTLY what I want here. Many thanks.
– tyke
Nov 13 '18 at 15:57
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276988%2findex-builtin-with-input%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The first argument of INDEX/2
should be a stream of the items to be indexed; here, .
is exactly what we want:
INDEX(.; .a + ":" + .b)
You're right. That is EXACTLY what I want here. Many thanks.
– tyke
Nov 13 '18 at 15:57
add a comment |
The first argument of INDEX/2
should be a stream of the items to be indexed; here, .
is exactly what we want:
INDEX(.; .a + ":" + .b)
You're right. That is EXACTLY what I want here. Many thanks.
– tyke
Nov 13 '18 at 15:57
add a comment |
The first argument of INDEX/2
should be a stream of the items to be indexed; here, .
is exactly what we want:
INDEX(.; .a + ":" + .b)
The first argument of INDEX/2
should be a stream of the items to be indexed; here, .
is exactly what we want:
INDEX(.; .a + ":" + .b)
answered Nov 13 '18 at 14:37
peakpeak
30.7k83957
30.7k83957
You're right. That is EXACTLY what I want here. Many thanks.
– tyke
Nov 13 '18 at 15:57
add a comment |
You're right. That is EXACTLY what I want here. Many thanks.
– tyke
Nov 13 '18 at 15:57
You're right. That is EXACTLY what I want here. Many thanks.
– tyke
Nov 13 '18 at 15:57
You're right. That is EXACTLY what I want here. Many thanks.
– tyke
Nov 13 '18 at 15:57
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276988%2findex-builtin-with-input%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please add example input and output to your question.
– oguzismail
Nov 13 '18 at 8:46
1
@oguzismail : examples added
– tyke
Nov 13 '18 at 10:30