PDA

View Full Version : mapping sparql json response to Ext.data.Record



StevenJ
10 Mar 2009, 11:50 AM
I'm wondering if the Ext.data.Record constructor is flexible enough to accommodate the default sparql (http://www.w3.org/TR/rdf-sparql-json-res/#examples) json output format? The example below is a typical response. The bindings array contains "name" : {"type":"literal", "value":"foo"}. The Record examples all have simple arrays of values. Would each object require a convert function to pull out the value? If that is the case, wouldn't it be more efficient to create a Record subclass that knows how to map the sparql types and values in these objects? Thanks.

sample sparql json response:


{
"head": {
"vars": [
"name",
"mbox"
]
},
"results": {
"bindings": [
{
"name" : {
"type": "literal",
"value": "Alice"
},

"mbox" : {
"type": "literal",
"value": ""
}
},{
"name" : {
"type": "literal",
"value": "Bob",
"xml:lang": "en"
},

"mbox" : {
"type": "uri",
"value": "mailto:[email protected]"
}
}
]
}
}


var emailRecord = Ext.data.Record.create([
{name: 'name'},
{name: 'mbox', mapping: 'email'}
]);

StevenJ
10 Mar 2009, 12:52 PM
Looks like I've solved my question, but I'll keep it here for anyone else digging through the documentation. The record can specify the specific object properties to map within the json response:



reader: new Ext.data.JsonReader({
root: 'results.bindings'
}, [
{ name:'name', mapping:'name.value'},
{ name:'mbox', mapping:'mbox.value'}
])