Skip to content

Instantly share code, notes, and snippets.

@kasei
Created January 2, 2020 17:22
Show Gist options
  • Save kasei/53002ac412d824fc2bcf0edca4eec4ff to your computer and use it in GitHub Desktop.
Save kasei/53002ac412d824fc2bcf0edca4eec4ff to your computer and use it in GitHub Desktop.
Issue with JSON-LD 1.1 optimization of @list

Expansion step 13.11 says:

If container mapping includes @list and expanded value is not already a list object, convert expanded value to a list object by first setting it to an array containing only expanded value if it is not already an array, and then by setting it to a map containing the key-value pair @list-expanded value.

In test t0004 I believe the recursive Expansion call in 13.9 for the mylist1 key will set expanded value to:

[
	{
		"@list": []
	}
]

The text in 13.11 will then turn this into a new map:

{
	"@list": [
		{
			"@list": []
		}
	]
}

instead of the value expected by the test:

[
	{
		"@list": []
	}
]

It's not clear to me where this double-@nest structure should be simplified. It seems related to 17.2 (which simplifies @set), and possibly to 19.1 which drops maps with only @value or @list keys, but *only when active property is null or @graph (which is not the case here).

@gkellogg
Copy link

gkellogg commented Jan 3, 2020

I think this is because of the same issue as in #295, where the expansion algorithm would formerly return an object, now always returns an array. When it returned an object, then 13.11 would have seen a list object, not an array containing a list object.

@gkellogg
Copy link

gkellogg commented Jan 3, 2020

This goes back to changes in #295. I think the change to always return an array came about because there is text at the end of the 1.0 algorithm, which is missing:

If, after the above algorithm is run, the result is a JSON object that contains only an @graph key, set the result to the value of @graph's value. Otherwise, if the result is null, set it to an empty array. Finally, if the result is not an array, then set the result to an array containing only the result.

This paragraph, which is run after the algorithm, so is not part of the recursive algorithm, got rolled into steps 20-22. We should probably revert the change from #295 which moved these up, and go back to the 1.0 description, so that when the expansion algorithm is passed an object, it typically returns an object, and not an array. We can re-examine some of the other changes that came as a consequence of this.

@kasei
Copy link
Author

kasei commented Jan 6, 2020

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