Bitcoin Forum
May 05, 2024, 09:19:38 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [SOLVED] JSON-RPC query syntax in curl  (Read 182 times)
.anto. (OP)
Full Member
***
Offline Offline

Activity: 179
Merit: 131


View Profile
February 28, 2019, 10:15:12 PM
Last edit: March 01, 2019, 08:53:15 AM by .anto.
 #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 <rpcuser>:<rpcpassword> --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 <rpcuser>:<rpcpassword> --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.
1714943978
Hero Member
*
Offline Offline

Posts: 1714943978

View Profile Personal Message (Offline)

Ignore
1714943978
Reply with quote  #2

1714943978
Report to moderator
1714943978
Hero Member
*
Offline Offline

Posts: 1714943978

View Profile Personal Message (Offline)

Ignore
1714943978
Reply with quote  #2

1714943978
Report to moderator
1714943978
Hero Member
*
Offline Offline

Posts: 1714943978

View Profile Personal Message (Offline)

Ignore
1714943978
Reply with quote  #2

1714943978
Report to moderator
The forum strives to allow free discussion of any ideas. All policies are built around this principle. This doesn't mean you can post garbage, though: posts should actually contain ideas, and these ideas should be argued reasonably.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714943978
Hero Member
*
Offline Offline

Posts: 1714943978

View Profile Personal Message (Offline)

Ignore
1714943978
Reply with quote  #2

1714943978
Report to moderator
.anto. (OP)
Full Member
***
Offline Offline

Activity: 179
Merit: 131


View Profile
March 01, 2019, 08: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/
.
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!