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

Proposal: new version of dag-json #129

Open
wants to merge 2 commits into
base: master
from
Open

Proposal: new version of dag-json #129

wants to merge 2 commits into from

Conversation

@mikeal
Copy link
Member

@mikeal mikeal commented Jun 11, 2019

This spec change would resolve the outstanding issue of dag-json not being able to represent the “/“ key.

Since “/“ is already reserved, we use that key for the version definition, which makes this new version backwards compatible with all of the existing dag-json data.

This change would also set up dag-json to store data outside of the actual node data, which could be used similar to how tags are used in cbor or for something like ipld/js-composites#3

block-layer/codecs/DAG-JSON.md Outdated Show resolved Hide resolved
@mikeal mikeal requested a review from vmx Jun 11, 2019

The internal data format is valid JSON but is **NOT** identical to the decoded
node data codecs produce.

This comment has been minimized.

@daviddias

daviddias Jun 11, 2019
Member

I do not understand why this is necessary. Is there a place with the rationale to make JSON not JSON?

This comment has been minimized.

@mikeal

mikeal Jun 11, 2019
Author Member

Right now, we’re using a reserved key, ”/“, for encoding links and binary. Several people think that key reservation is highly problematic because it means there are certain data sets you just can encode.

This change would fix that changing the internal block format. The format would *still be valid JSON, it just wouldn’t have as close of a 1-to-1 match with the decoded form of the data.

However, this change may not be worth it. This PR is to show that we have a solution to the reserved key issue and that is what it would take to fix it.

```javascript
{ "/": { "_": 1 },
"data": { "hello": "world", { "obj": { "array": [0, 0] } } },

This comment has been minimized.

@vmx

vmx Jun 11, 2019
Member

So those [0, 0] are placeholders? So if you want to encode [CID, "some string"] it would be [0, "some string"]?

This comment has been minimized.

@mikeal

mikeal Jun 11, 2019
Author Member

They are just placeholders to preserve the ordering of the array.

This comment has been minimized.

@vmx

vmx Jun 12, 2019
Member

I'd use null for that, but that's a minor detail. Perhaps the example could be expended to [null, "some string", null] to make it clearer that there are place holders which are mixed with actual values.

This comment has been minimized.

@mikeal

mikeal Jun 12, 2019
Author Member

originally it was null but i went with 0 because null encoding is extra bytes :/

block-layer/codecs/DAG-JSON.md Show resolved Hide resolved
block-layer/codecs/DAG-JSON.md Show resolved Hide resolved
```javascript
{ hello: 'world',
key: Buffer.from('value'),

This comment has been minimized.

@vmx

vmx Jun 11, 2019
Member

I would really prefer if we'd move to an Browser first approach and not using Node.js primitives:

    key: new TextEncoder().encode('value'),

This comment has been minimized.

@mikeal

mikeal Jun 11, 2019
Author Member

it’s just not entirely clear to everyone that this does binary encoding. perhaps we should just move to psuedo-code, something like Bytes(‘value’)

This comment has been minimized.

@vmx

vmx Jun 12, 2019
Member

That would work for me. I just don't want to give the impression it's a Node.js Buffer.

@mikeal mikeal changed the title spec: new version of dag-json Proposal: new version of dag-json Jun 11, 2019
@Stebalien
Copy link
Member

@Stebalien Stebalien commented Jun 12, 2019

Is the motivation just to support / keys? IMO, dag-json exists so users could read and write IPLD using JSON. I'm concerned this format looses that.

If we just want to support / in keys, we could use some form of escaping syntax. For full backwards compatibility, we could do something like {"/": {"literal": foobar}}. Alternatively, we can probably allow escaping forward slash without breaking too much: // -> /.

@mikeal
Copy link
Member Author

@mikeal mikeal commented Jun 12, 2019

IMO, dag-json exists so users could read and write IPLD using JSON. I'm concerned this format looses that.

I’m a little confused by this use case, because the dag-json codec already isn’t json. If you want to take a block of existing json data you should just use a json codec (which we should implement since it would be trivial).

If you want to take existing JSON data and add links to it, you’re going to have to use an encoding interface anyway and all of these details are invisible.

Is there a case I’m missing where you want dag-json instead of json and you’re interacting directly with the block format?

Is the motivation just to support / keys?

Yes, that’s the only thing we get out of this change. Using “/“ as a key will still be highly problematic for anyone using paths and selectors, but this would fix the issue at the codec level.

I’m actually not too worried about “/“ being reserved in dag-json but other people seem to be. I opened this PR to show what it would take to fix the issue, given some people are concerned.

@Stebalien
Copy link
Member

@Stebalien Stebalien commented Jun 12, 2019

I’m a little confused by this use case, because the dag-json codec already isn’t json. If you want to take a block of existing json data you should just use a json codec (which we should implement since it would be trivial).

dag-json wasn't designed to be 100% compatible but still mostly compatible. I agree we should have a plain JSON format for users who just want JSON but the point of this format was to provide a familiar, JSON-like format that mostly "just works" (i.e., you can link up existing JSON objects).

@vmx
Copy link
Member

@vmx vmx commented Jun 17, 2019

Another thing that might be worth keeping in mind. Having a format you can easily use as exchange format for tests: multiformats/rust-cid#17 (comment)

@vmx
Copy link
Member

@vmx vmx commented Aug 20, 2019

@mikeal We decided to put this into design history, but after having a closer look I think the discussion can be easily be summed up. Instead of having it archived automatically I suggest that we create a proper exploration report like https://github.com/ipld/specs/blob/035683c97d0280de5e2d490822d63ad618a8acab/design/history/exploration-reports/2019.06-unixfsv2-spike-01.md. @mikeal if you think it's worth having it there, could you please create a new PR with that report?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.