Author

Topic: [SOLVED] JSON-RPC query syntax in curl (Read 206 times)

full member
Activity: 179
Merit: 131
March 01, 2019, 03:48:42 AM
#2
Perhaps curl is the wrong tool for my purpose, or maybe because I cannot figure out the right syntax for that.

I have just found the solution for my purpose using jq tool (https://github.com/stedolan/jq). I found it to be a quite powerful tool for managing JSON data from command line.

For those who are looking for similar solution, here is the example of mine.
Code:
root@deeppurple:~$ bitcoin-cli getpeerinfo | jq -r '.[] | [.addr, .services, (.version|tostring), .subver] | join(",")'

The output for that is like the following:
Code:
[2001:41d0:2:af72::1]:8333,000000000000040d,70015,/Satoshi:0.17.0/
[2a01:4f8:10a:37ee::2]:25424,0000000000000000,70015,/Satoshi:0.15.1/
88.99.167.186:14287,0000000000000000,70015,/Satoshi:0.15.1/
[2a01:4f8:141:4d7::2]:8333,000000000000040d,70015,/Satoshi:0.17.0/
162.209.88.174:8333,000000000000040d,70015,/Satoshi:0.16.3/
[2a03:b0c0:2:d0::4bc:2001]:38160,0000000000000000,70015,/bitnodes.earn.com:0.1/
188.166.69.73:45169,0000000000000000,70015,/bitnodes.earn.com:0.1/
.
.
full member
Activity: 179
Merit: 131
February 28, 2019, 05:15:12 PM
#1
I would like to get only some parts of "getpeerinfo" output particularly the "addr", "services", "version" and "subver" of the peers, and put them into a list in text file. So far, I could not figure out the right JSON-RPC syntax to query that using curl.

I can get the entire output of "getpeerinfo" using curl command like below:
Code:
curl --user : --data-binary '{"jsonrpc": "1.0", "id":"getpeerinfo", "method": "getpeerinfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/

I assume that I have to put the right syntax on the "params" part, but I cannot find any information so far. I got errors when I tried for instance the following:
Code:
curl --user : --data-binary '{"jsonrpc": "1.0", "id":"getpeerinfo", "method": "getpeerinfo", "params": [{"addr"}]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null}

Could anyone give me hints please?

Thanks a lot in advance for your help.
Jump to: