Skip to content

How to iterate over name/value pairs of JSON objects? #219

@dennisvang

Description

@dennisvang

Issue type: ❓ Question

Suppose we have a JSON object like the following:

{
  "foo": "float",
  "bar": "integer"
}

I would like to iterate over the members of this JSON object, to generate RDF statements like the following, based on the member name and value, a.k.a. key/value:

ex:foo a ex:SomeClass ;  sh:datatype xsd:float .

ex:bar a ex:SomeClass ;  sh:datatype xsd:integer .

Is there some way to do this with YARRRML?

I tried accessing the member names using $.*~, as in https://github.com/JSONPath-Plus/JSONPath, but that does not seem to work.

Actually I was hoping for some solution like this:

prefixes:
  ex: "http://example.com/"

mappings:
  structures:
    sources:
      - access: data.json
        referenceFormulation: jsonpath
        iterator: "$.*"
    s: http://example.com/$(@.name)
    po:
      - [ a, ex:SomeClass ]
      - [ sh:datatype http://www.w3.org/2001/XMLSchema-datatypes#$(@.value) ]

Note that I'm aware I could first transform the object to an array of objects like below, using some out-of-band mechanism, but that's not what I'm looking for.

[
  {
    "name": "foo",
    "value": "float"
  },
  {
    "name": "bar",
    "value": "integer"
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions