0

I want to reference specific field of second schema in first schema through $ref keyword . secondSchema.json file:

{
   "store":{
      "book":[
         {
            "category":"A",
            "author":"AAAAAA",
            "title":"A Book",
            "price":111
         },
         {
            "category":"B",
            "author":"BBBBBBB",
            "title":"B Book",
            "price":222
         }
      ],
      "Vehicle":{
         "color":"red",
         "price":9999999
      }
   },
   "expensive":888
}

In first schema referencing the second schema like this:

  $ref:'secondSchema.json#/store.book.category'
  $ref:'secondSchema.json#/store.Vehicle.color'

I should be able to access exact nested element in second schema. How to achieve this?

Michał Ziober
  • 37,175
  • 18
  • 99
  • 146
user3824082
  • 1
  • 1
  • 4
  • 1
    `secondSchema.json` is not a valid `JSON`. Validate it using [jsonformatter](https://jsonformatter.curiousconcept.com) or other online tool. Also, take a look on [JsonPath](http://jsonpath.herokuapp.com/) tool and [library](https://github.com/json-path/JsonPath) – Michał Ziober Jul 31 '19 at 20:42
  • Could you please guide on how to reference a perticular atrribute in second schema through $ref. – user3824082 Aug 02 '19 at 05:06
  • `store.book.category` is a wrong path. It does not point to any category because there is an array. So, valid path should be `store.book.[*].category` or `store.book.[0].category` if you want to point to first element in book array. `store.Vehicle.color` properly points to `red` value. But I do not understand where points first pseudo path. Could you explain? – Michał Ziober Aug 02 '19 at 06:22

0 Answers0