Re: A library that converts regular JSON to JSON-LD

On Sun, 12 Apr 2020 at 08:47, Ivan Herman <ivan@w3.org> wrote:

> Melvin,
>
> an additional, albeit minor, point. If you have a large number of JSON
> files then modifying each of them might be a drag. However, if the files
> are served via HTTP to the processor, then it is also possible to deliver
> the context file (i.e., that one liner in your example, but possibly more
> complex ones as described in [1,2]) via an HTTP header. See [3] for further
> details.
>

Hi Ivan, thanks for this ingenious suggestions

I've gathered feedback from the 2 ML threads, the github issue, and the 2
stack overflow posts.  So far I have:

Proposals

   - Map a key foo to
      - urn:string:foo
      - urn:TEMP:foo
      - urn:{personal-or-app-namespace}:foo
   - Context file via HTTP header
      - Content-Type: application/json
      - Link: ; rel="http://www.w3.org/ns/json-ld#context";
      type="application/ld+json"
   - Nesting
      -

      the algorithm needs to recursively traverse the JSON tree and keep
      track of nesting to generate an @context that will keep nested properties
      of the same name distinct
      - Scoped contexts
      -

      {
        "@context": {
          "@vocab": "urn:TEST:",
          "baz": {"@context": {"@vocab": "baz/"}}
        },
        "@id": "http://example.com/#local-json",
        "foo": "bar",
        "baz": {
          "foo": "..."
        }


Information map below:

https://melvincarvalho.com/issues/2020/04/12/json-to-jsonld.html

And just for fun:  here's the JSON from that -- which is actually my use
case! :))

https://melvincarvalho.com/issues/2020/04/12/json-to-jsonld.json


>
> Cheers
>
> Ivan
>
>
> [1] https://github.com/w3c/EasierRDF/issues/29#issuecomment-606144041
> [2] https://github.com/w3c/EasierRDF/issues/29#issuecomment-606147345
> [3] https://www.w3.org/TR/json-ld11/#interpreting-json-as-json-ld
>
> On 11 Apr 2020, at 22:13, Melvin Carvalho <melvincarvalho@gmail.com>
> wrote:
>
>
>
> On Sat, 11 Apr 2020 at 21:40, james anderson <james@dydra.com> wrote:
>
>>
>> > On 2020-04-11, at 21:22:27, David Booth <david@dbooth.org> wrote:
>> >
>> > On 4/11/20 11:54 AM, Melvin Carvalho wrote:
>> >> Is there are library that converts simple json (think just a flat
>> object of key value pairs)
>> >> Into JSON-LD -- any value form will do, if some hacking of the context
>> is needed, that would be fine
>> >> If no library, is there an algorithm?
>> >> And if no algorithm, could we make one?
>> >
>> > I have not seen one yet, but it's good idea.  In particular, the
>> algorithm needs to recursively traverse the JSON tree and keep track of
>> nesting to generate an @context that will keep nested properties of the
>> same name distinct.
>>
>> the original request, above, concerned just “simple json”.
>>
>
>> >  See the discussion here:
>> > https://github.com/w3c/EasierRDF/issues/29
>>
>> while that discussion treats syntactic issues, neither it nor the cited
>> thread - in which a similar question two years ago from mr carvalho went
>> unanswered, approach the pertinent question: how is the context to effect
>> mappings from field names to meaningful terms?
>>
>
> Ah, good discussion, so the idea could be just add to the top:
>
>   "@context": {
>     "@vocab": "urn:{personal-or-app-namespace}:"
>   },
>
>
> And that should work for "simple json"
>
> In other words, "add a @vocab property and @context", then process what
> remains
>
> example:
>
> replace '{' at the start with
>
> > '{ "@context": { "@vocab": "urn:string:" },
>
> And then more complex JSON could expand on that algorithm.
>
> Now I have a 1 line shell script which can take ordinary JSON, and get at
> least some form of JSON-LD
>
> Does that sound about right?
>
>
>> >
>> > Once such an algorithm is defined, it could become a standard way to
>> map plain JSON to RDF.
>> >
>> > David Booth
>> >
>>
>> ---
>> james anderson | james@dydra.com | http://dydra.com
>
>
>
> ----
> Ivan Herman, W3C
> Home: http://www.w3.org/People/Ivan/
> mobile: +31-641044153
> ORCID ID: https://orcid.org/0000-0003-0782-2704
>
>

Received on Sunday, 12 April 2020 10:31:30 UTC