N
N
Nikolai2018-12-17 18:25:03
linux
Nikolai, 2018-12-17 18:25:03

How to make a json parser using curl?

I wrote a curl request, which, by design, should give the value of a certain json parameter:

curl --digest -L -D - --user login:password --header "Content-Type: application/json" "http://hostname/management/subsystem/datagrid-infinispan/cache-container/keycloak/distributed-cache/clientSessions?operation=resource&include-runtime=true&json.pretty=1" | jq -r '."number-of-entries-in-memory"'

When executing I get an error:
parse error: Invalid numeric literal at line 1, column 9

There is a suspicion that jq is confused by the absence of {} , because in theory, he should look for values ​​in these curly braces (json after all), and when a curl request is executed, headers are thrown into the terminal before and after authorization. Came to this opinion, because. if you write json to a file, then there is no such error:
curl --digest -L -D - --user login:password --header "Content-Type: application/json" "http://hostname/management/subsystem/datagrid-infinispan/cache-container/keycloak/distributed-cache/clientSessions?operation=resource&include-runtime=true&json.pretty=1" -o result.json && jq -r '."number-of-entries-in-memory"' result.json

Question: how to make a curl request so that after authorization (--digest -L -D) information about the header is not poured into the terminal? Or is the only option to write json to a file? :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2018-12-17
@brame

Your problem is in-D -

curl -s --digest -L --user login:password --header "Content-Type: application/json" "http://hostname/management/subsystem/datagrid-infinispan/cache-container/keycloak/distributed-cache/clientSessions?operation=resource&include-runtime=true&json.pretty=1" | jq -r '."number-of-entries-in-memory"'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question