1

Images of my json and query

enter image description here

Json code

{
    "reading_list": {
        "book": {
            "name": "Fifty shades of grey",
            "author": "E.L James",
            "date": "March 2015",
            "comment": "did not like it very much"
        },
        "book": {
            "name": "The grass is singing",
            "author": "Doris Lessing",
            "date": "April 2015",
            "comment": "enjoyed it quite a bit"
        },
        "book": {
            "name": "A short history of nearly everything",
            "author": "Bill Bryson",
            "date": "June 2015",
            "comment": "very informative"
        },
        "book": {
            "name": "JSON in 24 hours",
            "author": "Peter Settler",
            "date": "in the year",
            "comment": "read for work"
        },
        "book": {
            "name": "Miss Smilla's feeling for snow",
            "author": "Peter Hoeg's",
            "date": "in the year",
            "comment": "read for entertainment"
        }
    }
}

Query code:

for $x in reading_list
return $x("book")/name

as you can see from the link, i expected to get all the book names, but I only get:

Miss Smilla's feeling for snow.
The output should be like this:
Fifty shades of grey
A short history of nearly everything
The grass is singing
JSON in 24 hours
Miss Smilla's feeling for snow

What is wrong?.. Please help

Mukesh Ram
  • 6,248
  • 4
  • 19
  • 37
stardust
  • 13
  • 4

1 Answers1

0

In the JSONiq Data Model (JDM), duplicate keys (such as book in your example) are not allowed. It seems that this implementation doesn't throw an error but takes the last pair with that key.

In the original JSON RFC, this constraint is a SHOULD. You could increase interoperability by modelling the reading list as an array of books.

Ghislain Fourny
  • 6,971
  • 1
  • 30
  • 37