+1
Answered

Can I retrieve information from the datasource by a value other than it's order within the json file?

sovtek 7 years ago updated by icahill (Administrator) 7 years ago 6
Can I retrieve information from the datasource by a value other than it's order within the json file?

json node example:

"id":3550,
"name":"About Aaron",
"author":"",
"info":"",
"type":"Feature",
"pos":"3",
"tags":"tag1,tag2",
"contentUrl":"",
"range":2,
"imgSrc":"\/issue1661\/tocthumbs\/0003.jpg"

value="[datasource:storiesFeed.1.name]" would give me "About Aaron" if this was the first entry within the json feed.

What if it wasn't the first entry, and I wanted to grab the name by it's storyId instead of node order?
Without any knowledge of your actual source, I can only speculate. Some APIs allow you to drill down into your datasource URL to return a specific ID, you can replace that value with a variable in which you can then reassign as needed.

Example:

<assign property="var:productId" value="_productId" />
<assign property="datasource:redBox-kiosk-check.source" value="https://api.redbox.com/v3/inventory/stores/[preferences:kioskID]?products=[var:productId]&amp;apiKey=xxxxxxxxxxxxxxxxxxxxxxxxxx" />

When I use:

<assign property="object:STORYNAME.text" value="[datasource:storiesFeed.2.name]" />


It grabs the second entry within storiesFeed (which is a json file). The json file is located here:
https://joshdev.sendmyad.com/Vortex/s.... So the result of this code would be "About RG3".

Is there a way that I can simply edit this line of code:

<assign property="object:STORYNAME.text" value="[datasource:storiesFeed.2.name]" />


So that I can grab the value "name" by one of the nodes attributes. What if I wanted to get the value of "type", but did not want to grab it by the order of the node, what if i wanted to grab it by the id, which in this case would be '3553'.

Is there something I can write like:

<assign property="object:STORYNAME.text" value="[datasource:storiesFeed.id=3553.type]" />.
Yeah if you know or can assign the ID that you want, you can do this:


<assign property="var:node" value="5" />
<sync delay="2">
<alert message="[datasource:field-list.[var:node].name]"/>
</sync>
Right, but in your example aren't you grabbing the value of name by the order of the node in the datasource, which would be 5?
I want to grab the value of "name" by one of its siblings, not by the order of the node within the json feed...if that's possible.

In my very first example at the original post, I would like to grab the value of "name" by the value of "id", which in that case would be 3550. I know that I could use:


<assign property="object:STORYNAME.text" value="[datasource:storiesFeed.1.name]" />


to get the value of name if it was the first entry. But I want to get the value of name by the id.
Unfortunately JSON really doesn't have a query engine, there is no easy answer here. You could use javascript to breakdown the content of the JSON string but that might get you exactly where you want.