jq - print “-” for null valuesFiltering JSON request with JQ and bash scriptingHow to loop through json...
Bypass with wrong cvv of debit card and getting OTP
What is the difference between a historical drama and a period drama?
How do both sides know the MTU
Interview Question - Card betting
How many spells does my Bard 6/Wizard 1 know?
how can i make this execution plan more efficient?
Does the Defensive Duelist feat stack with the Warforged integrated protection?
Why is the order of my features changed when using readFeatures in OpenLayers v4.6.5?
Can a wizard delay learning new spells from leveling up to learn different spells later?
How can solar sailed ships be protected from space debris?
Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?
Term for a character that only exists to be talked to
What's the big deal about the Nazgûl losing their horses?
Contributing to a candidate as a Foreign National US Resident?
Does a multiclassed wizard start with a spellbook?
Is there a typical layout to blocking installed for backing in new construction framing?
Did Stalin kill all Soviet officers involved in the Winter War?
Do intermediate subdomains need to exist?
Do I need to be legally qualified to install a Hive smart thermostat?
How to deal with administrative duties killing the research spirit?
Can 4 Joy cons connect to the same Switch?
What is meaning of 4 letter abbreviations in Roman names like Titus Flavius T. f. T. n. Sabinus?
Why would "dead languages" be the only languages that spells could be written in?
Has chattel slavery ever been used as a criminal punishment in the USA since the passage of the Thirteenth Amendment?
jq - print “-” for null values
Filtering JSON request with JQ and bash scriptingHow to loop through json file?How to replace multiple lines with “sed” and convert to JSON?jq - select hostname starting from a stringjq - print values in one linereplace tab with spaceProcess JSON, containing new lines, with JQ and bashHow to parse json data using jq?Get values for a given key and its parent with jqJQ (GET ID based on NAME)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
input json:
{
"id": "3885",
"login": "050111",
"lastLoginTime": 1529730115000,
"lastLoginFrom": "192.168.66.230"
}
{
"id": "3898",
"login": "050112",
"lastLoginTime": null,
"lastLoginFrom": null
}
I want to get output for login, lastLoginTime and lastLoginFrom in tabulator delimited format:
050111 1529730115000 192.168.66.230
050112 - -
with below jq filter I get on output no "null" values which I could replace with "-"
$ jq -r '.|[.login, .lastLoginTime, .lastLoginFrom]|@tsv' test_json
050111 1529730115000 192.168.66.230
050112
Is there any other way to get "-" printed for such null values?
json jq
add a comment |
input json:
{
"id": "3885",
"login": "050111",
"lastLoginTime": 1529730115000,
"lastLoginFrom": "192.168.66.230"
}
{
"id": "3898",
"login": "050112",
"lastLoginTime": null,
"lastLoginFrom": null
}
I want to get output for login, lastLoginTime and lastLoginFrom in tabulator delimited format:
050111 1529730115000 192.168.66.230
050112 - -
with below jq filter I get on output no "null" values which I could replace with "-"
$ jq -r '.|[.login, .lastLoginTime, .lastLoginFrom]|@tsv' test_json
050111 1529730115000 192.168.66.230
050112
Is there any other way to get "-" printed for such null values?
json jq
add a comment |
input json:
{
"id": "3885",
"login": "050111",
"lastLoginTime": 1529730115000,
"lastLoginFrom": "192.168.66.230"
}
{
"id": "3898",
"login": "050112",
"lastLoginTime": null,
"lastLoginFrom": null
}
I want to get output for login, lastLoginTime and lastLoginFrom in tabulator delimited format:
050111 1529730115000 192.168.66.230
050112 - -
with below jq filter I get on output no "null" values which I could replace with "-"
$ jq -r '.|[.login, .lastLoginTime, .lastLoginFrom]|@tsv' test_json
050111 1529730115000 192.168.66.230
050112
Is there any other way to get "-" printed for such null values?
json jq
input json:
{
"id": "3885",
"login": "050111",
"lastLoginTime": 1529730115000,
"lastLoginFrom": "192.168.66.230"
}
{
"id": "3898",
"login": "050112",
"lastLoginTime": null,
"lastLoginFrom": null
}
I want to get output for login, lastLoginTime and lastLoginFrom in tabulator delimited format:
050111 1529730115000 192.168.66.230
050112 - -
with below jq filter I get on output no "null" values which I could replace with "-"
$ jq -r '.|[.login, .lastLoginTime, .lastLoginFrom]|@tsv' test_json
050111 1529730115000 192.168.66.230
050112
Is there any other way to get "-" printed for such null values?
json jq
json jq
asked Jun 23 '18 at 16:04
ChrisChris
3506 silver badges15 bronze badges
3506 silver badges15 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
use the alternative operator: //
so :
$jq -r '.|[.login, .lastLoginTime // "-" , .lastLoginFrom // "-" ]|@tsv' test_json
050111 1529730115000 192.168.66.230
050112 - -
2
The initial.|is not needed.
– Kusalananda♦
Jun 23 '18 at 16:30
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f451479%2fjq-print-for-null-values%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
use the alternative operator: //
so :
$jq -r '.|[.login, .lastLoginTime // "-" , .lastLoginFrom // "-" ]|@tsv' test_json
050111 1529730115000 192.168.66.230
050112 - -
2
The initial.|is not needed.
– Kusalananda♦
Jun 23 '18 at 16:30
add a comment |
use the alternative operator: //
so :
$jq -r '.|[.login, .lastLoginTime // "-" , .lastLoginFrom // "-" ]|@tsv' test_json
050111 1529730115000 192.168.66.230
050112 - -
2
The initial.|is not needed.
– Kusalananda♦
Jun 23 '18 at 16:30
add a comment |
use the alternative operator: //
so :
$jq -r '.|[.login, .lastLoginTime // "-" , .lastLoginFrom // "-" ]|@tsv' test_json
050111 1529730115000 192.168.66.230
050112 - -
use the alternative operator: //
so :
$jq -r '.|[.login, .lastLoginTime // "-" , .lastLoginFrom // "-" ]|@tsv' test_json
050111 1529730115000 192.168.66.230
050112 - -
edited 41 mins ago
miku
3882 silver badges15 bronze badges
3882 silver badges15 bronze badges
answered Jun 23 '18 at 16:28
EchoMike444EchoMike444
1,1702 silver badges8 bronze badges
1,1702 silver badges8 bronze badges
2
The initial.|is not needed.
– Kusalananda♦
Jun 23 '18 at 16:30
add a comment |
2
The initial.|is not needed.
– Kusalananda♦
Jun 23 '18 at 16:30
2
2
The initial
.| is not needed.– Kusalananda♦
Jun 23 '18 at 16:30
The initial
.| is not needed.– Kusalananda♦
Jun 23 '18 at 16:30
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f451479%2fjq-print-for-null-values%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