Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

What is the purpose of toJSON()? #57

Open
mikeal opened this issue Sep 13, 2018 · 1 comment
Open

What is the purpose of toJSON()? #57

mikeal opened this issue Sep 13, 2018 · 1 comment
Labels
kind/bug A bug in existing code (including security flaws) status/ready Ready to be worked

Comments

@mikeal
Copy link
Contributor

mikeal commented Sep 13, 2018

I'm a little confused by the toJSON() method.

First of all, we have doc comments for a typedef that doesn't actually exist called "SerializedCID". The docs claim toJSON() returns this but that isn't actually true.

In our toJSON() method we return 3 properties, one of which is a Buffer and, as a result, won't be property decodable from the JSON representation.

As I started to think about what toJSON() should do I realized that the most useful thing may be returning {"/": this.baseEncodedString()}. This touches again on the discussion we're having about a canonical JSON form for links but it does seem appropriate.

@vmx
Copy link
Member

vmx commented Sep 14, 2018

I agree. toJSON() should return something that is properly serializable with JSON.stringify(). I buffer is not.

@daviddias daviddias added kind/bug A bug in existing code (including security flaws) ready labels Oct 27, 2018
@Stebalien Stebalien added status/ready Ready to be worked and removed ready labels Mar 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug A bug in existing code (including security flaws) status/ready Ready to be worked
Projects
None yet
Development

No branches or pull requests

4 participants