Skip to content

Option to compact terms but not values #3

@gkellogg

Description

@gkellogg

_This was raised by Fabian Steeg:_

The JSON-LD API document states: "Expansion has two important goals: removing any contextual information from the document, and ensuring all values are represented in a regular form."

Is there a way to achieve only the second goal, the regular form, but with compact terms? Using compaction with compactArrays=false is pretty close, but there is still at least one thing that is irregular and causing issues for me.

Given this input:

{
  "http://example.com/foo": "foo-value",
  "http://example.com/bar": {
    "@value": "bar-value",
    "@language": "en"
  },
  "@context": {
    "foo": "http://example.com/foo",
    "bar": "http://example.com/bar"
  }
}

I get this from compaction with compactArrays=false:

{
  "@graph": [{
    "foo": ["foo-value"],              <-- foo: array of strings
    "bar": [{                          <-- bar: array of objects
      "@language": "en",
      "@value": "bar-value"
    }]
  }],
  "@context": {
    "foo": "http://example.com/foo",
    "bar": "http://example.com/bar"
  }
}

But I'd like to get this (which is what expansion does to the values):

{
  "@graph": [{
    "foo": [{                          <-- both foo and bar:
      "@value" : "foo-value"               array of objects
    }],
    "bar": [{
      "@language": "en",
      "@value": "bar-value"
    }]
  }],
  "@context": {
    "foo": "http://example.com/foo",
    "bar": "http://example.com/bar"
  }
}

So I guess I'm looking for something like a compactValues=false option.

Is there some way to get this output?

Original issue Option to compact terms but not values #338.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions