2

I am trying to import a descriptor into a blank wallet but I get a JSON parsing error.

$ cli createwallet "test" false true "" false true
$ cli -rpcwallet=test importdescriptors '[{ "desc": "pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)", "timestamp":1455191478, "internal": true }]'
error: Error parsing JSON: [{

Isn't the command importdescriptors expecting a JSON string? I can't see why I get this error. By the way this is an example from https://developer.bitcoin.org/reference/rpc/importdescriptors.html

Edit1.

The argument is a correct JSON string

$ export ARGS='[{ "desc": "pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)", "timestamp":1455191478, "internal": true }]'
$ echo $ARGS | jq
[
  {
    "desc": "pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)",
    "timestamp": 1455191478,
    "internal": true
  }
]
$ cli -rpcwallet=test importdescriptors $ARGS
error: Error parsing JSON: [{

I also tried changing single quotes with double quotes

$ export ARGS2="[{ \"desc\": \"pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)\", \"timestamp\":1455191478, \"internal\": true }]"
$ echo $ARGS2 | jq
[
  {
    "desc": "pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)",
    "timestamp": 1455191478,
    "internal": true
  }
]
$ cli -rpcwallet=test importdescriptors $ARGS2 
error: Error parsing JSON: [{

I am using a bash shell.

Edit2.

As suggested by @andrew-chow, removing the spaces solves the JSON parsing error, this is weird. I tried a simple C++ application in my bash shell that reads arguments from the command line and anything inside single or double quotes is interpreted as a single string argument independently of spaces.

int main(int nargs, char** args)
2
  • 2
    Try removing spaces in your json string.
    – Ava Chow
    Commented Feb 15, 2023 at 17:47
  • importdescriptors is expecting a JSON string, and I was able to copy/paste your example and get a result (although, your example is missing a checksum and will result in an error). Are you sure you aren't missing a closing single quote?
    – josie
    Commented Feb 15, 2023 at 17:54

1 Answer 1

0

The error is dependent on shell. In cmd (Windows) try:

bitcoin-cli.exe -rpcwallet=test importdescriptors "[{ \"desc\": \"pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)\", \"timestamp\":1455191478, \"internal\": true }]"

It will not work the same with PowerShell.

In bash the dollar sign before the single quote may make difference (altough your initial command example works in Bash in my environment without the "error: Error parsing JSON: [{"):

$ bitcoin-cli -rpcwallet=test importdescriptors $'[{ "desc": "pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)", "timestamp":1455191478, "internal": true }]'
1
  • OP is using a bash or similar shell, I believe. Commented Feb 15, 2023 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.