Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get only "name" from below json #1278

Closed
jankooooooz opened this issue Oct 5, 2018 · 6 comments
Closed

how to get only "name" from below json #1278

jankooooooz opened this issue Oct 5, 2018 · 6 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@jankooooooz
Copy link

[{"name":"local.tar.gz.part-ab","hash":"99f7ff566a910064f774fee3acc06287","bytes":5368709120,"last_modified":"2018-10-05T16:07:37.841000","content_type":"binary/octet-stream"},{"name":"local.tar.gz.part-ac","hash":"8fab90eaff4c5c447e0076b508e11a9e","bytes":5368709120,"last_modified":"2018-10-05T16:12:21.569000","content_type":"binary/octet-stream"},{"name":"local.tar.gz.part-ad","hash":"fd2c9aec58b0de0b13117245c6baf62a","bytes":5368709120,"last_modified":"2018-10-05T16:16:54.336000","content_type":"binary/octet-stream"},{"name":"local.tar.gz.part-ae","hash":"26188ef13ec623382748faf7f7a380b2","bytes":2329785943,"last_modified":"2018-10-05T16:18:53.909000","content_type":"binary/octet-stream"},{"name":"vmohswbre024_admin.tar.gz.aa","hash":"83f43b790013c1633e354bbc0a0fd4e9","bytes":4194304000,"last_modified":"2018-10-05T17:53:40.375000","content_type":"binary/octet-stream"}]

@nlohmann
Copy link
Owner

nlohmann commented Oct 6, 2018

Assuming the JSON text above is in some file input.json:

std::ifstream i("input.json");
json j = json::parse(i);

// iterate the outer array
for (json& entry : j)
{
  // output the value at the "name" key
  std::cout << entry["name"] << std::endl;
}

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Oct 6, 2018
@nlohmann
Copy link
Owner

nlohmann commented Oct 9, 2018

@rijeshvp Do you need further support?

@jankooooooz
Copy link
Author

Yes... please .. I forgot to mention that i am looking for a unix command... Will you be able to help me to have a unix command to extract the name element out of it.

@nlohmann
Copy link
Owner

You should try jq:

cat input.json | jq ".name"

@jankooooooz
Copy link
Author

I am getting this output when i am running following. so i will not be redirecting this to a file.. want to format it on the fly
curl -l -X GET
-u ${username}:${token}
-x abc-proxy.server.com:80
https://swiftobjectstorage.us-${region}-1.oraclecloud.com/v1/${tenancy}/${bucket}/${object}

@nlohmann
Copy link
Owner

Please have a look at this tutorial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants