Skip to content

dag-json vs. json: is json trully json? #470

@hacdias

Description

@hacdias

Hi!

We're considering supporting actual json and cbor data formats in Kubo (ref). As I was testing if JSON worked properly, I run into the following:

~ ❯ ipfs dag put --input-codec json --store-codec json
ipfs: Reading from /dev/stdin; send Ctrl-d to stop.
{ 10: "hello" }
Error: unexpected int token while expecting map key

After looking at the code, it seems that the codec json actually uses the codec dag-json for decoding (and encoding), which means that json doesn't support many of the features of real JSON.

// Decode deserializes data from the given io.Reader and feeds it into the given datamodel.NodeAssembler.
// Decode fits the codec.Decoder function interface.
//
// This is the function that will be registered in the default multicodec registry during package init time.
func Decode(na datamodel.NodeAssembler, r io.Reader) error {
return dagjson.DecodeOptions{
ParseLinks: false,
ParseBytes: false,
}.Decode(na, r)
}

Is this a bug, or not? If not, why? If yes, are there any plans for fixing this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions