diff --git a/src/input-parser/JSONParser.js b/src/input-parser/JSONParser.js index 727683c..5e8943b 100644 --- a/src/input-parser/JSONParser.js +++ b/src/input-parser/JSONParser.js @@ -21,7 +21,12 @@ class JsonParser { resultType: selector.startsWith('PATH~') ? 'pointer' : 'value', }) .filter((e) => e !== null && e !== undefined) // null values are ignored (undefined shouldn't happens since input is json) - .map((e) => e.toString()); // return only strings + .map((e) => { + if (Array.isArray(e)) { + return e.map((eItem) => eItem.toString()); + } + return e.toString(); + }); // return only strings } } diff --git a/tests/arrayValueMapping/input.json b/tests/arrayValueMapping/input.json new file mode 100644 index 0000000..6f926df --- /dev/null +++ b/tests/arrayValueMapping/input.json @@ -0,0 +1,4 @@ +{ + "name":"Tom A.", + "favorite-numbers": [ 3, 33, 13 ] +} diff --git a/tests/arrayValueMapping/mapping.ttl b/tests/arrayValueMapping/mapping.ttl new file mode 100644 index 0000000..17430d5 --- /dev/null +++ b/tests/arrayValueMapping/mapping.ttl @@ -0,0 +1,33 @@ +@prefix rr: . +@prefix rml: . +@prefix schema: . +@prefix ql: . +@base . #the base for the classes + +<#LOGICALSOURCE> +rml:source "./tests/arrayValueMapping/input.json"; +rml:referenceFormulation ql:JSONPath; +rml:iterator "$". + + +<#Mapping> + rml:logicalSource <#LOGICALSOURCE>; + + rr:subjectMap [ + rr:termType rr:BlankNode; + rr:class schema:Person; + ]; + + + rr:predicateObjectMap [ + rr:predicateMap [ rr:constant "http://schema.org/name" ]; + rr:objectMap [ rml:reference "name" ]; + ]; + + rr:predicateObjectMap [ + rr:predicateMap [ rr:constant "http://example.com/favorite-numbers" ]; + rr:objectMap [ + rml:reference "favorite-numbers" ; + rr:datatype "http://www.w3.org/2001/XMLSchema#integer" ; + ]; + ] . diff --git a/tests/arrayValueMapping/out.json b/tests/arrayValueMapping/out.json new file mode 100644 index 0000000..29f6d04 --- /dev/null +++ b/tests/arrayValueMapping/out.json @@ -0,0 +1,21 @@ +[ + { + "@type": "http://schema.org/Person", + "http://schema.org/name": "Tom A.", + "http://example.com/favorite-numbers": [ + { + "@value": "3", + "@type": "http://www.w3.org/2001/XMLSchema#integer" + }, + { + "@type": "http://www.w3.org/2001/XMLSchema#integer", + "@value": "33" + }, + { + "@type": "http://www.w3.org/2001/XMLSchema#integer", + "@value": "13" + } + ], + "@id": "_:http%3A%2F%2Fsti2.at%2F%23Mapping_1" + } +] \ No newline at end of file diff --git a/tests/test.js b/tests/test.js index 1a692ab..9694239 100644 --- a/tests/test.js +++ b/tests/test.js @@ -39,6 +39,22 @@ it('Basic straight double mapping', async () => { assert.equal(result.length, 2); }); +it('Array Value mapping', async () => { + const options = {}; + let result = await parser.parseFile('./tests/arrayValueMapping/mapping.ttl', './tests/arrayValueMapping/out.json', options).catch((err) => { console.log(err); }); + result = helper.cutArray(result); + assert.equal(result['http://schema.org/name'], 'Tom A.'); + assert.equal(result['http://example.com/favorite-numbers'].length, 3); + assert.equal(result['http://example.com/favorite-numbers'][0]['@value'], '3'); + assert.equal(result['http://example.com/favorite-numbers'][0]['@type'], 'http://www.w3.org/2001/XMLSchema#integer'); + assert.equal(result['http://example.com/favorite-numbers'][1]['@value'], '33'); + assert.equal(result['http://example.com/favorite-numbers'][1]['@type'], 'http://www.w3.org/2001/XMLSchema#integer'); + assert.equal(result['http://example.com/favorite-numbers'][2]['@value'], '13'); + assert.equal(result['http://example.com/favorite-numbers'][2]['@type'], 'http://www.w3.org/2001/XMLSchema#integer'); + assert.equal(result['@type'], 'http://schema.org/Person'); + assert.equal(Object.keys(result).length, 4); +}); + it('Live mapping', async () => { const options = { // baseMapping:["http://sti2.at/#SPORTSmapping"],