Get the value of key from JSON response got from the curl url in unix Without using jq [duplicate]
This question already has an answer here:
Parsing JSON with Unix tools
36 answers
I have written the shell script and getting JSON result from the curl.
I want to get the value of key form JSON response without using unix tools like jq, python etc.
Thanks in advance.
shell unix awk
marked as duplicate by Raedwald, shellter, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 28 '18 at 8:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Parsing JSON with Unix tools
36 answers
I have written the shell script and getting JSON result from the curl.
I want to get the value of key form JSON response without using unix tools like jq, python etc.
Thanks in advance.
shell unix awk
marked as duplicate by Raedwald, shellter, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 28 '18 at 8:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
So, what JSON do you have, what part do you want to extract and how does your current code fail? Please edit your post and show the Minimal, Complete, and Verifiable example.
– Corion
Nov 26 '18 at 14:09
@Corion Please have a look at the answer I posted and let me know if you have optimal solution.
– Rupesh Patil
Nov 28 '18 at 7:13
add a comment |
This question already has an answer here:
Parsing JSON with Unix tools
36 answers
I have written the shell script and getting JSON result from the curl.
I want to get the value of key form JSON response without using unix tools like jq, python etc.
Thanks in advance.
shell unix awk
This question already has an answer here:
Parsing JSON with Unix tools
36 answers
I have written the shell script and getting JSON result from the curl.
I want to get the value of key form JSON response without using unix tools like jq, python etc.
Thanks in advance.
This question already has an answer here:
Parsing JSON with Unix tools
36 answers
shell unix awk
shell unix awk
edited Nov 28 '18 at 7:19
Rupesh Patil
asked Nov 26 '18 at 13:10
Rupesh PatilRupesh Patil
12
12
marked as duplicate by Raedwald, shellter, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 28 '18 at 8:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Raedwald, shellter, tripleee
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 28 '18 at 8:08
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
So, what JSON do you have, what part do you want to extract and how does your current code fail? Please edit your post and show the Minimal, Complete, and Verifiable example.
– Corion
Nov 26 '18 at 14:09
@Corion Please have a look at the answer I posted and let me know if you have optimal solution.
– Rupesh Patil
Nov 28 '18 at 7:13
add a comment |
2
So, what JSON do you have, what part do you want to extract and how does your current code fail? Please edit your post and show the Minimal, Complete, and Verifiable example.
– Corion
Nov 26 '18 at 14:09
@Corion Please have a look at the answer I posted and let me know if you have optimal solution.
– Rupesh Patil
Nov 28 '18 at 7:13
2
2
So, what JSON do you have, what part do you want to extract and how does your current code fail? Please edit your post and show the Minimal, Complete, and Verifiable example.
– Corion
Nov 26 '18 at 14:09
So, what JSON do you have, what part do you want to extract and how does your current code fail? Please edit your post and show the Minimal, Complete, and Verifiable example.
– Corion
Nov 26 '18 at 14:09
@Corion Please have a look at the answer I posted and let me know if you have optimal solution.
– Rupesh Patil
Nov 28 '18 at 7:13
@Corion Please have a look at the answer I posted and let me know if you have optimal solution.
– Rupesh Patil
Nov 28 '18 at 7:13
add a comment |
1 Answer
1
active
oldest
votes
Got the solution,
I am getting following JSON response from curl and storing in variable :
CURL_OUTPUT='{ "url": "protocol://xyz.net/9999" , "other_key": "other_value" }'
Question :I want to read the url key value and extract the id from that url:
Answer : _ID=$(echo $CURL_OUTPUT |awk '{print $2}' FS='url":' |awk '{print $1}' FS=',' | awk '{print $2}' FS='"'|awk '{print $4}' FS='/')
That is a bit of overkill -- 4 calls toawkand 4 calls toprintfwithin a command substitution -- that's a minimum of 9-subshells spawned plus 4 pipes just to parse'9999'. Better to make a single call togrepassign the result to a temporary variable and then use the shell parameter expansion to delete up to the last'/', e.g.tmp=$(echo "$CURL_OUTPUT" | grep -o 'protocol[^", ]*'); _ID="${tmp##*/}"
– David C. Rankin
Nov 28 '18 at 7:22
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Got the solution,
I am getting following JSON response from curl and storing in variable :
CURL_OUTPUT='{ "url": "protocol://xyz.net/9999" , "other_key": "other_value" }'
Question :I want to read the url key value and extract the id from that url:
Answer : _ID=$(echo $CURL_OUTPUT |awk '{print $2}' FS='url":' |awk '{print $1}' FS=',' | awk '{print $2}' FS='"'|awk '{print $4}' FS='/')
That is a bit of overkill -- 4 calls toawkand 4 calls toprintfwithin a command substitution -- that's a minimum of 9-subshells spawned plus 4 pipes just to parse'9999'. Better to make a single call togrepassign the result to a temporary variable and then use the shell parameter expansion to delete up to the last'/', e.g.tmp=$(echo "$CURL_OUTPUT" | grep -o 'protocol[^", ]*'); _ID="${tmp##*/}"
– David C. Rankin
Nov 28 '18 at 7:22
add a comment |
Got the solution,
I am getting following JSON response from curl and storing in variable :
CURL_OUTPUT='{ "url": "protocol://xyz.net/9999" , "other_key": "other_value" }'
Question :I want to read the url key value and extract the id from that url:
Answer : _ID=$(echo $CURL_OUTPUT |awk '{print $2}' FS='url":' |awk '{print $1}' FS=',' | awk '{print $2}' FS='"'|awk '{print $4}' FS='/')
That is a bit of overkill -- 4 calls toawkand 4 calls toprintfwithin a command substitution -- that's a minimum of 9-subshells spawned plus 4 pipes just to parse'9999'. Better to make a single call togrepassign the result to a temporary variable and then use the shell parameter expansion to delete up to the last'/', e.g.tmp=$(echo "$CURL_OUTPUT" | grep -o 'protocol[^", ]*'); _ID="${tmp##*/}"
– David C. Rankin
Nov 28 '18 at 7:22
add a comment |
Got the solution,
I am getting following JSON response from curl and storing in variable :
CURL_OUTPUT='{ "url": "protocol://xyz.net/9999" , "other_key": "other_value" }'
Question :I want to read the url key value and extract the id from that url:
Answer : _ID=$(echo $CURL_OUTPUT |awk '{print $2}' FS='url":' |awk '{print $1}' FS=',' | awk '{print $2}' FS='"'|awk '{print $4}' FS='/')
Got the solution,
I am getting following JSON response from curl and storing in variable :
CURL_OUTPUT='{ "url": "protocol://xyz.net/9999" , "other_key": "other_value" }'
Question :I want to read the url key value and extract the id from that url:
Answer : _ID=$(echo $CURL_OUTPUT |awk '{print $2}' FS='url":' |awk '{print $1}' FS=',' | awk '{print $2}' FS='"'|awk '{print $4}' FS='/')
answered Nov 28 '18 at 7:06
Rupesh PatilRupesh Patil
12
12
That is a bit of overkill -- 4 calls toawkand 4 calls toprintfwithin a command substitution -- that's a minimum of 9-subshells spawned plus 4 pipes just to parse'9999'. Better to make a single call togrepassign the result to a temporary variable and then use the shell parameter expansion to delete up to the last'/', e.g.tmp=$(echo "$CURL_OUTPUT" | grep -o 'protocol[^", ]*'); _ID="${tmp##*/}"
– David C. Rankin
Nov 28 '18 at 7:22
add a comment |
That is a bit of overkill -- 4 calls toawkand 4 calls toprintfwithin a command substitution -- that's a minimum of 9-subshells spawned plus 4 pipes just to parse'9999'. Better to make a single call togrepassign the result to a temporary variable and then use the shell parameter expansion to delete up to the last'/', e.g.tmp=$(echo "$CURL_OUTPUT" | grep -o 'protocol[^", ]*'); _ID="${tmp##*/}"
– David C. Rankin
Nov 28 '18 at 7:22
That is a bit of overkill -- 4 calls to
awk and 4 calls to printf within a command substitution -- that's a minimum of 9-subshells spawned plus 4 pipes just to parse '9999'. Better to make a single call to grep assign the result to a temporary variable and then use the shell parameter expansion to delete up to the last '/', e.g. tmp=$(echo "$CURL_OUTPUT" | grep -o 'protocol[^", ]*'); _ID="${tmp##*/}"– David C. Rankin
Nov 28 '18 at 7:22
That is a bit of overkill -- 4 calls to
awk and 4 calls to printf within a command substitution -- that's a minimum of 9-subshells spawned plus 4 pipes just to parse '9999'. Better to make a single call to grep assign the result to a temporary variable and then use the shell parameter expansion to delete up to the last '/', e.g. tmp=$(echo "$CURL_OUTPUT" | grep -o 'protocol[^", ]*'); _ID="${tmp##*/}"– David C. Rankin
Nov 28 '18 at 7:22
add a comment |
2
So, what JSON do you have, what part do you want to extract and how does your current code fail? Please edit your post and show the Minimal, Complete, and Verifiable example.
– Corion
Nov 26 '18 at 14:09
@Corion Please have a look at the answer I posted and let me know if you have optimal solution.
– Rupesh Patil
Nov 28 '18 at 7:13