1

I'm trying to execute the below request payload (JSON) and getting the response back as below:

CURL command:

curl --header "Content-Type: application/json" --header "hostname:kindle.qa.amazon.com" \
--request POST \
--data '{
"country":"BE",
"cardNumberPayment":"9423-8234-1882-3412",
"cardType" : "Visa",
"expirationMonth": "12",
"expirationYear": "2020"
}' \
  http://amazon.qa.payment.com/v1/Services/restservices/credit

Response:

{"cardType":"Visa","cardNumber":"9423823418823409","cvv":"***"}
{"cardType":"Visa","cardNumber":"9423823418823411","cvv":"***"}
{"cardType":"Visa","cardNumber":"9423823418823410","cvv":"***"}

I just want to get cardNumber for the curl command instead of printing the entire JSON (Except cardType, and cvv).

Expected Output:

9423823418823409
9423823418823411
9423823418823410

I just want to get the list of card numbers alone to print as output. How can I achieve this?

ArrchanaMohan
  • 2,314
  • 4
  • 36
  • 84

1 Answers1

10

You'll have to use a JSON parser to extract the information. You can use jq to do that (jq is a lightweight and command-line JSON processor.)

This article describes more in detail how to achieve that. They also have a tutorial here.

For instance

curl 'http://amazon.qa.payment.com/v1/Services/restservices/credit' | jq '.[0]'

would extract the first element of your array (assuming it's an array - your code makes it look like a series of objects).

Then to grab the card number do sthg along the lines of

jq '.[0] | .cardNumber'

There are several other examples in this SO post too.

David Brossard
  • 13,584
  • 6
  • 55
  • 88