# Extract nested object

**URL:** <https://community.cratedb.com/t/extract-nested-object/1670>\
**Category:** CrateDB\
**Created:** [December 13, 2023, 7:38pm UTC](https://community.cratedb.com/t/extract-nested-object/1670 "2023-12-13T19:38:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yosi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/yosi/32/1135_2.png) [@Yosi](https://community.cratedb.com/u/Yosi)\
**Post date:** [December 13, 2023, 7:38pm UTC](https://community.cratedb.com/t/extract-nested-object/1670/1 "2023-12-13T19:38:30Z")

</div>

Greetings

Spent a few hours looking at docs but not getting what I need to extract specific data from nested jsonlike data

This is my data in an OBJECT date type column

```auto
{
	"actionType": "append",
	"entities": [
		{
			"name": {
				"type": "Text",
				"value": "Corner Unit"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 50
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.3986112,
						52.554699
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit001",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:001"
			}
		},
		{
			"name": {
				"type": "Text",
				"value": "Wall Unit 1"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 100
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.3987221,
						52.554664
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit002",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:001"
			}
		},
		{
			"name": {
				"type": "Text",
				"value": "Wall Unit 2"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 100
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.3987221,
						52.554664
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit003",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:001"
			}
		},
		{
			"name": {
				"type": "Text",
				"value": "Corner Unit"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 50
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.390311,
						52.507522
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit004",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:002"
			}
		},
		{
			"name": {
				"type": "Text",
				"value": "Long Wall Unit"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 200
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.390309,
						52.50751
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit005",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:002"
			}
		},
		{
			"name": {
				"type": "Text",
				"value": "Corner Unit"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 50
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.4447112,
						52.503199
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit006",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:003"
			}
		},
		{
			"name": {
				"type": "Text",
				"value": "Wall Unit 1"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 100
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.4447221,
						52.503164
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit007",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:003"
			}
		},
		{
			"name": {
				"type": "Text",
				"value": "Wall Unit 2"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 100
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.4447221,
						52.503164
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit008",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:003"
			}
		},
		{
			"name": {
				"type": "Text",
				"value": "Corner Unit"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 50
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.444711,
						52.503122
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit009",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:003"
			}
		},
		{
			"name": {
				"type": "Text",
				"value": "Long Wall Unit"
			},
			"maxCapacity": {
				"type": "Integer",
				"value": 200
			},
			"location": {
				"type": "geo:json",
				"value": {
					"coordinates": [
						13.4094111,
						52.5208028
					],
					"type": "Point"
				}
			},
			"id": "urn:ngsi-ld:Shelf:unit010",
			"type": "Shelf",
			"refStore": {
				"type": "Relationship",
				"value": "urn:ngsi-ld:Store:004"
			}
		}
	]
}

```

The following is my query but I am not getting what I need

```auto
SELECT store_details,
  store_details['entities']['name']['value'] nm,
  store_details['entities']['location']['value']['coordinates'] coordinates
FROM doc.berliner

```

Could you please point me to doc so that I get a final result that looks like this?

```auto
name,lon,lat
Bösebrücke Einkauf,13.3986,52.5547
Checkpoint Markt,13.3903,52.5075
East Side Galleria,13.4447,52.5031
Tower Trödelmarkt,13.4094,52.5208

```

---

<div class="post-metadata">

**Author:** ![hernanc](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/hernanc/32/676_2.png) [@hernanc](https://community.cratedb.com/u/hernanc)\
**Post date:** [December 13, 2023, 9:43pm UTC](https://community.cratedb.com/t/extract-nested-object/1670/2 "2023-12-13T21:43:23Z")

</div>

Hi,  
Try this

```sql
with myrows as (select unnest(store_details['entities'] ) as obj 
   from berliner)
select obj['name']['value'] as name
,obj['location']['value']['coordinates'][1] as lon
,obj['location']['value']['coordinates'][2] as lat
from myrows;

```

---

<div class="post-metadata">

**Author:** ![Yosi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/yosi/32/1135_2.png) [@Yosi](https://community.cratedb.com/u/Yosi)\
**Post date:** [December 14, 2023, 12:30am UTC](https://community.cratedb.com/t/extract-nested-object/1670/3 "2023-12-14T00:30:57Z")

</div>

Yes it works beautiful!

 ![image](https://us1.discourse-cdn.com/flex020/uploads/crate/original/2X/6/61913d1a2822d0fb79330d71aa42331429fd874e.png)
