Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow array values in json #33

Merged
merged 3 commits into from
Jul 7, 2022

Conversation

adlerfaulkner
Copy link
Contributor

Fixes #32

@ThibaultGerrier
Copy link
Collaborator

Ideally the .getData would always return string[] - the list of element where each element should get a new triple.
With your changes here it would now return (string|string[])[]. For some reason this still works and produces the expected result (because the code has a bunch of helper.addArray() and helper.curArray() sprinkled after getting the data)

Because of this it is now possible to create invalid json-ld. For instance:
in the mapping: rml:reference "favorite-numbers.*" ;
in the data: "favorite-numbers": [[ 3, 33, 13 ], 1]
the resulting invalid jsonld: "@value": [ "3", "33", "13" ],
where instead this should default back to the "old" mode and output 2 triples, one with "@value": "3,33,13" and the other with 1

I think the easiest way to fix this would be to make this case of "one element collection with an array" explicit
something like:

    const arr =  JSONPath({
      path: `${this.paths[index]}${splitter}${sel}`,
      json: this.json,
      resultType: selector.startsWith('PATH~') ? 'pointer' : 'value',
    })
      .filter((e) => e !== null && e !== undefined)

    if(arr.length === 1 && Array.isArray(arr[0])) {
      return arr[0].map(e => e.toString())
    }
    return arr.map(e => e.toString())

that way the return type also stays string[]

@adlerfaulkner
Copy link
Contributor Author

adlerfaulkner commented Jul 7, 2022

@ThibaultGerrier sounds good. Pushed a change with your suggestion.

@ThibaultGerrier ThibaultGerrier merged commit e57e5d6 into semantifyit:master Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON array values get turned into strings
2 participants