Skip to content

Commit 4ce2b70

Browse files
committed
Don't always use arrays for @graph.
Fixes 1.0 compatibility issue.
1 parent 59ec447 commit 4ce2b70

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# jsonld ChangeLog
22

3+
### Fixed
4+
- Don't always use arrays for `@graph`. Fixes 1.0 compatibility issue.
5+
36
## 1.0.0 - 2018-02-28
47

58
### Notes

lib/compact.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ api.compact = ({
385385
nestResult, itemActiveProperty, compactedItem,
386386
{propertyIsArray: (!options.compactArrays || container.includes('@set'))});
387387
} else {
388-
// wrap using @graph alias, value is always an array
389-
if(!_isArray(compactedItem)) {
390-
compactedItem = [compactedItem]
388+
// wrap using @graph alias, remove array if only one item
389+
if(_isArray(compactedItem) && compactedItem.length === 1) {
390+
compactedItem = compactedItem[0];
391391
}
392392
compactedItem = {
393393
[api.compactIri({activeCtx, iri: '@graph', relativeTo: {vocab: true}})]: compactedItem

0 commit comments

Comments
 (0)