<p>Using bitcoinjs you can generate a keyPair with the following code:</p>

<pre><code>var keyPair = bitcoin.ECPair.makeRandom();
</code></pre>

<p>How can I stringify this object to JSON and then parse it back to an object? JSON doesn't play well with circular objects and I'm struggling to understand how one can work around this. </p>

<p>Thanks,</p>

<p>Connor</p>

CC BY-SA 3.0
2016-12-06T11:27:02.473Z
Why would you stringify keyPair? Is it the public key / private key / address you wish to use for further processing? Or the details in the keyPair object?
Shabahat M. Ayubi
CC BY-SA 3.0
2016-12-06T15:15:11.170Z
@ShabahatM.Ayubi I wish to use details in the keyPair object. Specifically I'm trying to see if I can essentially transfer the entire keyPair from one device to another. (I understand this would be a horrible idea security wise if the keyPairs were actively being used for their original purpose)
user1929274
CC BY-SA 3.0
2016-12-07T11:41:41.617Z
I fail to understand why would you do that. I tried going through the src folder of bitcoinjs-lib module. The ECpair go through tonnes of calculations before being converted into some form which is useful.
Also I cannot understand the difference between JSON and object, both are the same. Do you wish to convert a JSON to string and vice versa?
Shabahat M. Ayubi
<bitcoinjs>
How to convert a keyPair to JSON and back?
user1929274
# How to convert a keyPair to JSON and back?

(Asked by: username_0 on 2016-12-05)

Using bitcoinjs you can generate a keyPair with the following code:

```
var keyPair = bitcoin.ECPair.makeRandom();

```

How can I stringify this object to JSON and then parse it back to an object? JSON doesn't play well with circular objects and I'm struggling to understand how one can work around this.

Thanks,

Connor

**Tags:** bitcoinjs

> **Comments:**
> **username_1**: Why would you stringify keyPair? Is it the public key / private key / address you wish to use for further processing? Or the details in the keyPair object?  
> **username_0**: @username_1 I wish to use details in the keyPair object. Specifically I'm trying to see if I can essentially transfer the entire keyPair from one device to another. (I understand this would be a horrible idea security wise if the keyPairs were actively being used for their original purpose)  
> **username_1**: I fail to understand why would you do that. I tried going through the src folder of bitcoinjs-lib module. The ECpair go through tonnes of calculations before being converted into some form which is useful. Also I cannot understand the difference between JSON and object, both are the same. Do you wish to convert a JSON to string and vice versa?  

---

## 0 answers

