JSON is really simple.
Start a hierarchy with {
and close it with }
.
Elements have a name and a value.
The name is always in quotes.
The value can be:
- number
- String (in quotes)
- an array of values, denoted by
["value1", "value2"]
, the first value is at location [0]
- a sub-section of JSON denoted by
{ "element1": "foo", "element2": "bar"}
That’s it. That’s all there is to it.
JSONPATH is a way to navigate down the hierarchy of name/value pairs. $
means the root of the JSON documents. Then reference the elements by name. If the value of an element is an array, use [n]
to reference the nth element of the array.
Given:
{
"flight_number": 93,
"mission_name": "Starlink 6",
"mission_id": [],
"launch_year": "2020",
"launch_date_unix": 1587583800,
"launch_date_utc": "2020-04-22T19:30:00.000Z",
"launch_date_local": "2020-04-22T15:30:00-04:00",
"is_tentative": false,
"tentative_max_precision": "hour",
"tbd": false,
"launch_window": null,
"rocket": {
"rocket_id": "falcon9",
"rocket_name": "Falcon 9",
"rocket_type": "FT",
"first_stage": {
"cores": [
{
"core_serial": "B1051",
"flight": 4,
"block": 5,
"gridfins": true,
"legs": true,
"reused": true,
"land_success": true,
"landing_intent": true,
"landing_type": "ASDS",
"landing_vehicle": "OCISLY"
}
]
},
"second_stage": {
"block": 5,
"payloads": [
{
"payload_id": "Starlink 6",
"norad_id": [
72000
],
"reused": false,
"customers": [
"SpaceX"
],
"nationality": "United States",
"manufacturer": "SpaceX",
"payload_type": "Satellite",
"payload_mass_kg": 15400,
"payload_mass_lbs": 33951.2,
"orbit": "VLEO",
"orbit_params": {
"reference_system": "geocentric",
"regime": "very-low-earth",
"longitude": null,
"semi_major_axis_km": null,
"eccentricity": null,
"periapsis_km": null,
"apoapsis_km": null,
"inclination_deg": null,
"period_min": null,
"lifespan_years": null,
"epoch": null,
"mean_motion": null,
"raan": null,
"arg_of_pericenter": null,
"mean_anomaly": null
}
}
]
},
"fairings": {
"reused": true,
"recovery_attempt": false,
"recovered": null,
"ship": "GOMSTREE"
}
},
"ships": [
"OCISLY",
"GOMSTREE",
"GOMSCHIEF"
],
"telemetry": {
"flight_club": null
},
"launch_site": {
"site_id": "ksc_lc_39a",
"site_name": "KSC LC 39A",
"site_name_long": "Kennedy Space Center Historic Launch Complex 39A"
},
"launch_success": true,
"links": {
"mission_patch": "https://images2.imgbox.com/d2/3b/bQaWiil0_o.png",
"mission_patch_small": "https://images2.imgbox.com/9a/96/nLppz9HW_o.png",
"reddit_campaign": "https://www.reddit.com/r/spacex/comments/fxkc7k/starlink6_launch_campaign_thread/",
"reddit_launch": "https://www.reddit.com/r/spacex/comments/g5jmx0/rspacex_starlink_6_official_launch_discussion/",
"reddit_recovery": "https://www.reddit.com/r/spacex/comments/g6kztd/rspacex_starlink_v1_l6_recovery_discussion/",
"reddit_media": "https://www.reddit.com/r/spacex/comments/g5fqka/rspacex_starlink6_media_thread_photographer/",
"presskit": "https://www.spacex.com/sites/spacex/files/seventh_starlink_mission_overview.pdf",
"article_link": "https://spaceflightnow.com/2020/04/22/spacexs-starlink-network-surpasses-400-satellite-mark-after-successful-launch/",
"wikipedia": "https://en.wikipedia.org/wiki/Starlink",
"video_link": "https://youtu.be/wSge0I7pwFI",
"youtube_id": "wSge0I7pwFI",
"flickr_images": [
"https://live.staticflickr.com/65535/49673373182_93a517e140_o.jpg",
"https://live.staticflickr.com/65535/49672551378_fabc17ef6f_o.jpg",
"https://live.staticflickr.com/65535/49672551303_564ce21658_o.jpg",
"https://live.staticflickr.com/65535/49806771628_fef13c852d_o.jpg",
"https://live.staticflickr.com/65535/49807633862_e5abcb41a6_o.jpg"
]
},
"details": "This mission will launch the sixth batch of operational Starlink satellites, which are expected to be version 1.0, from SLC-40, Cape Canaveral AFS. It is the seventh Starlink launch overall. The satellites will be delivered to low Earth orbit and will spend a few weeks maneuvering to their operational altitude of 550 km. The booster for this mission is expected to land on OCISLY.",
"upcoming": false,
"static_fire_date_utc": "2020-04-17T11:48:00.000Z",
"static_fire_date_unix": 1587687810,
"timeline": null,
"crew": null,
"last_date_update": "2020-04-22T17:41:33.000Z",
"last_ll_launch_date": "2020-04-22T19:30:00.000Z",
"last_ll_update": "2020-04-22T17:41:33.000Z",
"last_wiki_launch_date": "2020-04-22T19:30:00.000Z",
"last_wiki_revision": "7eb594bf-84a3-11ea-b698-0e120e32abbf",
"last_wiki_update": "2020-04-22T14:13:53.000Z",
"launch_date_source": "launch_library"
}
JSONPATH Expression |
value |
notes |
$.flight_number |
93 |
|
$.rocket.rocket_id |
“falcon9” |
|
$.rocket.first_stage.cores[0].flight |
4 |
Only one value in the array value for cores |
$.ships[0] |
“OCISLY” |
three values in the array, get the first one |
$.ships[2] |
“GOMSCHIEF”. |
three values in the array, get the third one |
$.telemetry |
“flight_club”: null |
notice this is itself a piece of JSON, not just a single string or number |
It’s only if there is an array value you want to select from and you need to do some math to determine which element you want to select that you need to use JavaScript to extract the values.
Search for “JSON syntax” and “JSONPATH tutorial”. Both are standards and neither were invented by openHAB.