<p>I think the problem is that you are trying to pass the file name as an argument instead of the content of the file. Try passing the json through the standard input instead:</p>

<pre><code>cat routes.json | lncli --network=testnet sendtoroute --payment_hash=...
</code></pre>

CC BY-SA 4.0
2019-02-11T11:42:43.757Z
using this i get: 

[lncli] unable to unmarshal json string from incoming array of routes: invalid character 'â' looking for beginning of value
Stefano Angieri
CC BY-SA 4.0
2019-02-11T11:46:55.723Z
Interesting. Just in case, I assume you do not have a character like this in your routes.json?
Dmitry Laptev
CC BY-SA 4.0
2019-02-11T11:50:02.620Z
Exactly. The content of routes.json is just the output of the queryroutes command.
Stefano Angieri
CC BY-SA 4.0
2019-02-11T13:01:36.503Z
Could you also try passing the routes as a std input? “cat routes.json | lncli sendtoroute ...”
Dmitry Laptev
CC BY-SA 4.0
2019-02-11T13:23:18.403Z
Well passing the routes as std input works! It is a good workaround.
Stefano Angieri
CC BY-SA 4.0
2019-02-11T14:13:44.307Z
I am still puzzled why `--routes="$(cat routes.json)"` does not work for you. For me it succeeds, but maybe there are some bash differences.
Dmitry Laptev
CC BY-SA 4.0
2019-02-11T14:26:20.267Z
Ok, Actually it works. I was missing the final "-". 

Here the command: 
lncli --network=testnet sendtoroute --payment_hash=03bd33db2dfdebff50ca8a7ae3bade681bbf7f25246248c9416b4441b1dbf4c2  --routes="$(cat routes.json)" -
Stefano Angieri
CC BY-SA 4.0
2019-02-11T11:35:40.797Z
2019-02-11T13:42:57.717Z
2019-02-11T13:42:57.717Z
Dmitry Laptev
<p>From <code>lncli network=testnet sendtoroute -h</code>:</p>

<pre><code>NAME: 
lncli sendtoroute - send a payment over a predefined route
USAGE:
lncli sendtoroute [command options] [arguments...]
DESCRIPTION:
Send a payment over Lightning using a specific route. One must specify
a list of routes to attempt and the payment hash. This command can even
be chained with the response to queryroutes. This command can be used
to implement channel rebalancing by crafting a self-route, or even
atomic swaps using a self-route that crosses multiple chains.
There are three ways to specify routes:
 * using the --routes parameter to manually specify a JSON encoded
   set of routes in the format of the return value of queryroutes:
       (lncli sendtoroute --payment_hash=&lt;pay_hash&gt; --routes=&lt;route&gt;)

 * passing the routes as a positional argument:
       (lncli sendtoroute --payment_hash=pay_hash &lt;route&gt;)

 * or reading in the routes from stdin, which can allow chaining the
   response from queryroutes, or even read in a file with a set of
   pre-computed routes:
       (lncli queryroutes --args.. | lncli sendtoroute --payment_hash= -

   notice the '-' at the end, which signals that lncli should read
   the route in from stdin
OPTIONS:
--payment_hash value, --pay_hash value  the hash to use within the payment's HTLC
--routes value, -r value                a json array string in the format of the response of queryroutes that denotes which routes to use
</code></pre>

<p>I use this command to save the routes in a json file: </p>

<pre><code>lncli -network=testnet queryroutes 02e34c1b4c5f8e7419cf4d10e3bc9651d46dc1af68df6a7b81a24951a9192aa9c4 --final_cltv_delta=144 25000-&gt;routes.json
</code></pre>

<p>Then from the spec, performing:</p>

<pre><code>lncli --network=testnet sendtoroute --payment_hash=03bd33db2dfdebff50ca8a7ae3bade681bbf7f25246248c9416b4441b1dbf4c2 --routes=routes.json
</code></pre>

<p>I always get back this error: </p>

<pre><code>[lncli] unable to unmarshal json string from incoming array of routes: invalid character 'r' looking for beginning of value
</code></pre>

<p>Am I doing something wrong?  What should I set as --routes parameter? </p>

<lightning-network><lightning-network-daemon><lightning-routing><micropaymentchannels><lncli>
How to send a payment through a route saved in a json?
Stefano Angieri
# How to send a payment through a route saved in a json?

(Asked by: username_0 on 2019-02-11)

From `lncli network=testnet sendtoroute -h`:

```
NAME: 
lncli sendtoroute - send a payment over a predefined route
USAGE:
lncli sendtoroute [command options] [arguments...]
DESCRIPTION:
Send a payment over Lightning using a specific route. One must specify
a list of routes to attempt and the payment hash. This command can even
be chained with the response to queryroutes. This command can be used
to implement channel rebalancing by crafting a self-route, or even
atomic swaps using a self-route that crosses multiple chains.
There are three ways to specify routes:
 * using the --routes parameter to manually specify a JSON encoded
   set of routes in the format of the return value of queryroutes:
       (lncli sendtoroute --payment_hash=<pay_hash> --routes=<route>)

 * passing the routes as a positional argument:
       (lncli sendtoroute --payment_hash=pay_hash <route>)

 * or reading in the routes from stdin, which can allow chaining the
   response from queryroutes, or even read in a file with a set of
   pre-computed routes:
       (lncli queryroutes --args.. | lncli sendtoroute --payment_hash= -

   notice the '-' at the end, which signals that lncli should read
   the route in from stdin
OPTIONS:
--payment_hash value, --pay_hash value  the hash to use within the payment's HTLC
--routes value, -r value                a json array string in the format of the response of queryroutes that denotes which routes to use

```

I use this command to save the routes in a json file:

```
lncli -network=testnet queryroutes 02e34c1b4c5f8e7419cf4d10e3bc9651d46dc1af68df6a7b81a24951a9192aa9c4 --final_cltv_delta=144 25000->routes.json

```

Then from the spec, performing:

```
lncli --network=testnet sendtoroute --payment_hash=03bd33db2dfdebff50ca8a7ae3bade681bbf7f25246248c9416b4441b1dbf4c2 --routes=routes.json

```

I always get back this error:

```
[lncli] unable to unmarshal json string from incoming array of routes: invalid character 'r' looking for beginning of value

```

Am I doing something wrong? What should I set as --routes parameter?

**Tags:** lightning-network, lightning-network-daemon, lightning-routing, micropaymentchannels, lncli


---

## 1 answers

### Answer by username_1 on 2019-02-11. Score: 3 | Accepted answer

I think the problem is that you are trying to pass the file name as an argument instead of the content of the file. Try passing the json through the standard input instead:

```
cat routes.json | lncli --network=testnet sendtoroute --payment_hash=...

```

> **Comments:**
> **username_0**: using this i get:   [lncli] unable to unmarshal json string from incoming array of routes: invalid character 'â' looking for beginning of value  
> **username_1**: Interesting. Just in case, I assume you do not have a character like this in your routes.json?  
> **username_0**: Exactly. The content of routes.json is just the output of the queryroutes command.  
> **username_1**: Could you also try passing the routes as a std input? “cat routes.json | lncli sendtoroute ...”  
> **username_0**: Well passing the routes as std input works! It is a good workaround.  
> **username_1**: I am still puzzled why `--routes="$(cat routes.json)"` does not work for you. For me it succeeds, but maybe there are some bash differences.  
> **username_0**: Ok, Actually it works. I was missing the final "-".   Here the command:  lncli --network=testnet sendtoroute --payment_hash=03bd33db2dfdebff50ca8a7ae3bade681bbf7f25246248c9416b4441b1dbf4c2  --routes="$(cat routes.json)" -  

---

