Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toJSON? #54

Closed
alanshaw opened this issue Feb 28, 2018 · 5 comments
Closed

Add toJSON? #54

alanshaw opened this issue Feb 28, 2018 · 5 comments

Comments

@alanshaw
Copy link
Member

If I JSON.stringify(multiaddr('/ip4/127.0.0.1')) I get "{\"buffer\":{\"type\":\"Buffer\",\"data\":[4,127,0,0,1]}}" should it be '/ip4/127.0.0.1' instead?

@daviddias
Copy link
Member

isn't that what you get from toString()?

@alanshaw
Copy link
Member Author

yes, should the JSON representation be the same?

@daviddias
Copy link
Member

Not sure. JSON can provide more information than a String, i.e it could have a toJSON that already divided the multiaddr into tuples

@alanshaw
Copy link
Member Author

There's no info missing in the string representation though...other than "I am a multiaddr", but neither representation says this atm.

Right now JSON.parse(JSON.stringify(multiaddr('/ip4/127.0.0.1'))) is not a valid multiaddr (not machine or human readable), but if toJSON returned '/ip4/127.0.0.1' then it would be a valid, human readable multiaddr, and I could also do this:

multiaddr(JSON.parse(JSON.stringify(multiaddr('/ip4/127.0.0.1'))))

Of note, if you give a multiaddr to IPFS config then bad things happen because a stringified multiaddr is saved to a JSON config file and read out as something it's not.

new IPFS({
  config: {
    Addresses: { Swarm: [multiaddr('...')] }
  }
})

@jacobheun
Copy link
Contributor

Added in 6.0.6

@ghost ghost removed the status/ready Ready to be worked label Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants