Step: Generic Object Index: .["foo"]

Generic Object Index: .["foo"]

In the previous lesson we talked about $

You can also do the same with $.["foo"] or $.foo["bar"] or $["foo"]["bar"]

$.foo works only for identifier-like strings, if your key has any special characters like trunk-space, you have to use $.["trunk-space"]).

Now let's see if you can get postal code from the example JSON.

  "firstName": "Charles",
  "lastName": "Doe",
  "location": {
    "city": "San Francisco",
    "postal-code": "94103"