3

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?

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.