Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Issues and Decisions table

Issue/Question

Decision

Problem Statement

When a list is fetched using Get a node API then instead of returning a JSON list containing n-number of list items, the API returns each list item as individual JSON object. And each of these JSON objects have same name as the list name.

For example: if there is a list named books, with xpath /bookstore/categories[@code=4]/books, containing 2 books named Book 1 and Book 2.

 List node named "books" under parent node xpath: /bookstore/categories[@code=4]
[
    {
        "categories": {
            "code": "4",
            "name": "Computing",
            "books": [
                {
                    "title": "Book 1",
                    "lang": "N/A",
                    "price": 11,
                    "editions": [2009]
                },
                {
                    "lang": "German",
                    "price": 39,
                    "title": "Debian GNU/Linux",
                    "editions": [2007, 2013, 2021]
                }
            ]
        }
    }
]

When fetching this list using get a node API we get a parent JSON list containing two individual JSON objects. Where each JSON object is named books and under these two objects we have the books named book1 and book 2.

 List "books" when fetched using xpath to list node: /bookstore/categories[@code=4]/books
[
    {
        "books": {
            "title": "Book 1",
            "lang": "N/A",
            "price": 11,
            "editions": [2009]
        }
    },
    {
        "books": {
            "title": "Book 2",        
            "lang": "German",
            "price": 39,
            "editions": [2007, 2013, 2021]
        }
    }
]

This output makes the JSON inconsistent from the original data and difficult to work with because when fetching a list node it is expected to get the entire list as is rather than each list item being returned as individual JSON objects.

The expected output should be of the following format

 Click here to expand...
[
  {
    "books": [
      {
            "title": "Book 1",
            "lang": "N/A",
            "price": 11,
            "editions": [2009]
      },
      {
            "title": "Book 2",        
            "lang": "German",
            "price": 39,
            "editions": [2007, 2013, 2021]
      }
    ]
  }
]

Comparision with Query Node API

When the same list node is accessed using Query a Node API, we get the same response as described above where each list item is fetched as individual JSON object with same name as the list.

 List "books" when queried using Query a Node API with xpath to list node: /bookstore/categories[@code=4]/books
[
    {
        "books": {
            "title": "Book 1",
            "lang": "N/A",
            "price": 11,
            "editions": [2009]
        }
    },
    {
        "books": {
            "title": "Book 2",        
            "lang": "German",
            "price": 39,
            "editions": [2007, 2013, 2021]
        }
    }
]

Associated problems

The inconsistency described above extends to CPS Delta feature when using it to compare list nodes.

This is because the delta feature shares the logic/code of Get a Node API to fetch the data nodes from the data base before generating the delta.

So, when comparing JSON containing a list, to a list fetched from the data base, an inconsistent delta is generated because logically the JSON list supplied as input by the user is compared to the first JSON object of the same name, returned by the code. This comparison can be imagined as follows:

 Visual comparison of data when JSON list is provided by user and compared to JSON list fetched from database

JSON list provided by user

JSON objects fetched from database

{
    "books": [
      {
            "title": "Book 1",
            "lang": "N/A",
            "price": 11,
            "editions": [2009]
      },
      {
            "title": "Book 2",        
            "lang": "German",
            "price": 39,
            "editions": [2007, 2013, 2021]
      }
    ]
  }
[
    {
        "books": {
            "title": "Book 1",
            "lang": "N/A",
            "price": 11,
            "editions": [2009]
        }
    },
    {
        "books": {
            "title": "Book 2",        
            "lang": "German",
            "price": 39,
            "editions": [2007, 2013, 2021]
        }
    }
]

Proposed Solution

WIP

  • No labels