Friday tip of the day: use 'jq' to parse json

@daviddavis reminded me of a nice utility I learned about recently: jq[1]. I use it quite often in scripts involving container images where I need the long sha256 to reference them.

sudo skopeo inspect --raw docker-daemon:
satellite.example.com:5000/examplecorp-docker_hub-alpine:3.4 | jq '.config
.digest'
Enjoy!

[1] https://stedolan.github.io/jq/tutorial/

Thanks for sharing, looks very useful indeed and didn’t know about it

– Ivan

···

On Fri, 8 Dec 2017 at 22:00, Tom McKay thomasmckay@redhat.com wrote:

@daviddavis reminded me of a nice utility I learned about recently: jq[1].
I use it quite often in scripts involving container images where I need the
long sha256 to reference them.

sudo skopeo inspect --raw docker-daemon:
satellite.example.com:5000/examplecorp-docker_hub-alpine:3.4 | jq
’.config | .digest’

Enjoy!

[1] https://stedolan.github.io/jq/tutorial/


You received this message because you are subscribed to the Google Groups
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jq is really cool, and super fast. Thanks for the reminder to learn some
more about it.

···

On Friday, December 8, 2017 at 4:00:11 PM UTC-5, Tom McKay wrote:

@daviddavis reminded me of a nice utility I learned about recently: jq[1].
I use it quite often in scripts involving container images where I need the
long sha256 to reference them.

sudo skopeo inspect --raw docker-daemon:
satellite.example.com:5000/examplecorp-docker_hub-alpine:3.4 | jq
’.config | .digest’

Enjoy!

[1] https://stedolan.github.io/jq/tutorial/

Tuestday tip of the day: use jo[1] to generate JSON from shell :wink:

[1] https://github.com/jpmens/jo

···

On Mon, Dec 11, 2017 at 8:01 AM, Ivan Necas inecas@redhat.com wrote:

Thanks for sharing, looks very useful indeed and didn’t know about it

– Ivan

On Fri, 8 Dec 2017 at 22:00, Tom McKay thomasmckay@redhat.com wrote:

@daviddavis reminded me of a nice utility I learned about recently: jq[1].
I use it quite often in scripts involving container images where I need the
long sha256 to reference them.

sudo skopeo inspect --raw
docker-daemon:satellite.example.com:5000/examplecorp-docker_hub-alpine:3.4 |
jq ‘.config | .digest’

Enjoy!

[1] https://stedolan.github.io/jq/tutorial/


You received this message because you are subscribed to the Google Groups
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to the Google Groups
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Beste Grüße/Kind regards,

Evgeni Golov
Software Engineer


Red Hat GmbH, http://www.de.redhat.com/, Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Michael Cunningham, Michael
O’Neill, Eric Shander

Any idea how to make the output pipe-able? Eg:

echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq

works well and, as expected, I get:

{
  "value": "New",
  "onclick": "CreateNewDoc()"
}

But I can't pipe that output to anything else and if I do:

echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq | grep value

this just errors out printing the tool usage guidelines.

···

On Friday, December 8, 2017 at 2:00:11 PM UTC-7, Tom McKay wrote:

@daviddavis reminded me of a nice utility I learned about recently: jq[1].
I use it quite often in scripts involving container images where I need the
long sha256 to reference them.

sudo skopeo inspect --raw docker-daemon:
satellite.example.com:5000/examplecorp-docker_hub-alpine:3.4 | jq
'.config | .digest'

Enjoy!

[1] https://stedolan.github.io/jq/tutorial/

You can access the value directly as if it were a javascript property: jq
-r .value - Check the online docs, there are tons of options for
mapping/fitlering/selecting/etc... This is probably thee best tool for
working with api's on the command line.

Also getting back to your actual question, use quotes: jq

···

On Tue, Dec 19, 2017 at 6:36 PM, James Shewey <jdshewey@gmail.com> wrote:

Any idea how to make the output pipe-able? Eg:

echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq

works well and, as expected, I get:

{
  "value": "New",
  "onclick": "CreateNewDoc()"
}

But I can't pipe that output to anything else and if I do:

echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq | grep value

this just errors out printing the tool usage guidelines.

On Friday, December 8, 2017 at 2:00:11 PM UTC-7, Tom McKay wrote:

@daviddavis reminded me of a nice utility I learned about recently:
jq[1]. I use it quite often in scripts involving container images where I
need the long sha256 to reference them.

sudo skopeo inspect --raw docker-daemon:satellite.exampl
e.com:5000/examplecorp-docker_hub-alpine:3.4 | jq '.config | .digest'

Enjoy!

[1] https://stedolan.github.io/jq/tutorial/

--
You received this message because you are subscribed to the Google Groups
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.