How to convert a keyPair to JSON and back? 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
Wallet Import Format can be used in a Javascript String,  which is JSON compatible.
For bitcoinjs-lib@^2.0.0:


  var prv = keyPair.toWIF()


To recover, use


  bitcoin.ECPair.fromWIF(prv)


Caution: if you store your private key in an insecure location, your funds will be insecure. fromWIF/toWIF does not provide any form 
of protection.