RMLio / yarrrml-parser

A YARRRML parser library and CLI in Javascript
MIT License
41 stars 17 forks source link

How to handle keys in JSON, that contain dots? #191

Closed amirwesthoff closed 1 year ago

amirwesthoff commented 1 year ago

My (example) data in JSON has dots in its keys, which I would like to keep that way. As shown below, I am able to work with the other data fields, but the data with dots in its keys, does not get transformed.

How can I adjust my RML (and YARRRML) mapping, to make this work? In case it's important: in my actual data the keys consist of numbers and dots. I have tried things like double quotes around the field name, but that doesn't seem to work.

I am using RMLmapper 6.0.0.-r363

Example data:

[
    {
      "id": "001",
      "name": "Person A",
      "address.street": "Street X"
    },
    {
      "id": "002",
      "name": "Person B",
      "address.street": "Street Y"
    }
]

Mapping (YARRRML):

prefixes:
  ex: http://www.example.com/
  dbo: http://dbpedia.org/ontology/
  grel: http://users.ugent.be/~bjdmeest/function/grel.ttl#
  schema: http://schema.org/
  xsd: "http://www.w3.org/2001/XMLSchema#"
  foaf: "http://xmlns.com/foaf/0.1/"
  idlab-fn: "http://example.com/idlab/function/"

sources:
  example-source: ['input/example.json~jsonpath', "$.[*]"]

mappings:
  examples:
    sources: example-source
    s: ex:$(id)
    po:
      - [a, ex:Person]
      - [ex:name, $(name)]
      - [ex:streetAddress, $(address.street)]

Mapping (RML, as converted using yarrrml-parser):

# only the problematic predicate-object mapping shown

:pom_002 rdf:type rr:PredicateObjectMap ;
    rr:predicateMap :pm_002 ;
    rr:objectMap :om_002 .

:pm_002 rdf:type rr:PredicateMap ;
    rr:constant ex:streetAddress .

:om_002 rdf:type rr:ObjectMap ;
    rml:reference "address.street" ;
    rr:termType rr:Literal .

Result:

@prefix ex: <http://www.example.com/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:001 a ex:Person; 
  ex:name "Person A" . # predicate-object for ex:streetAddress missing

ex:002 a ex:Person;
  ex:name "Person B" . # predicate-object for ex:streetAddress missing

Expected/Desired result:

@prefix ex: <http://www.example.com/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:001 a ex:Person;
  ex:name "Person A" ;
  ex:streetAddress "Street X" .

ex:002 a ex:Person;
  ex:name "Person B" ;
  ex:streetAddress "Street Y" .
bjdmeest commented 1 year ago

@amirwesthoff I transfered your issue to be more findable later on:

The problem is that JSONPath has a specific way of dealing with dots in the key, which YARRRML must take into account because we make use of JSONPath :).

Using something like - [ex:streetAddress, '$(["address.street"])'] should result into rml:reference "[\"address.street\"]" ; which will give the correct results.