Asinox
Asinox

Reputation: 6865

How to select a specific record from a JSON source in YQL?

I'm trying to use YQL to get some data form a JSON source, but I'm getting NULL.

This is the JSON:

{
  "categorias": [
    {
      "id": 0,
      "categoryName": "Seguridad",
      "description": "Protegete contra vulnerabilidades practicando correctamente la seguridad en el desarrollo de software",
      "imageUrl": "http://domain/img_thmb/lock.png",
      "tutorials": [
        {
          "id": 1,
          "name": "Cross-Site request forgery (CSRF) para dummies",
          "description": "Continuando con el tema de seguridad, vamos a analizar lo básico de un ataque CSRF para que puedan entender como funciona y poder protegerse del mismo.",
          "tutorialUrl": "http://domain/post/6529205521/cross-site-request-forgery-csrf-para-dummies",
          "imageUrl": "http://domain/lmsnt9akJ81qjthf4.jpg"
        },
        {
          "id": 2,
          "name": "Cross-site scripting (XSS) para dummies",
          "description": "De acuerdo al OWASP el Cross-site scripting es una de las amenazas mas explotadas en el 2010.",
          "tutorialUrl": "http://domain/post/6511050937/cross-site-scripting-xss-para-dummies",
          "imageUrl": "http://domain/lmrfitzlmu1qjthf4.jpg"
        }
      ]
    },.....

This is the select statement I'm using in the YQL Console:

select * from json where url='http://domain/js/json.js' and id=1

I'm trying to get the "categorias ID" and I'm getting null, what am I doing wrong?

Upvotes: 0

Views: 684

Answers (2)

salathe
salathe

Reputation: 51960

Another option is to use the itemPath key to specify what should be considered an individual result.

select * from json
where itemPath="json.categorias" 
  and url="<url to json>" 
  and id=1;

Upvotes: 1

Asinox
Asinox

Reputation: 6865

Im sorry, im new with YQL, im answering my own question, if there's some new too:

select categorias from json where url='http://domain/js/json.js' and categorias.id=1

Upvotes: 1

Related Questions