# How to access nested json in vega

**URL:** <https://discuss.elastic.co/t/how-to-access-nested-json-in-vega/140721>\
**Category:** Kibana\
**Created:** [July 19, 2018, 12:17pm UTC](https://discuss.elastic.co/t/how-to-access-nested-json-in-vega/140721 "2018-07-19T12:17:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narasimma\_varman](https://avatars.discourse-cdn.com/v4/letter/n/e56c9b/32.png) [@Narasimma\_varman](https://discuss.elastic.co/u/Narasimma_varman)\
**Post date:** [July 19, 2018, 12:17pm UTC](https://discuss.elastic.co/t/how-to-access-nested-json-in-vega/140721/1 "2018-07-19T12:17:42Z")

</div>

I am using vega in kibana. I try to access nested json field but I cannot able to access that field, could anyone help me to resolve this issue. I attach my vega json and index name is pie

index data sample:

{ "\_index": "pie", "\_type": "flare", "\_id": "2", "\_version": 1, "\_score": 1, "\_source": { "id": 2, "parent": 1, "data" :{ "memory": 50 } } }

```
{
"$schema": "https://vega.github.io/schema/vega/v3.json",
"data": [
{
"name": "table",
"url": {

"%context%": "true",

 "index": "pie*",

 "body": {

  "size": "10"

 }
 },

"format": { "property": "hits.hits" },

"transform": [
 {
  "type": "formula",
  "expr": "toNumber(datum[\"_source\"][\"data\"][\"memory\"])",
  "as": "memory"
    }
      ],
 "transform": [{"type": "pie", "field": "memory"}]
 } ],

  "scales": [
   {
 "name": "r",
  "type": "sqrt",
  "domain": {"data": "table", "field": "memory"},
 "zero": true,
 "range": [20, 100]
     }
   ],

 "marks": [
{
 "type": "arc",
  "from": {"data": "table"},
  "encode": {
   "enter": {
    "x": {"field": {"group": "width"}, "mult": 0.5},
  "y": {"field": {"group": "height"}, "mult": 0.5},
  "startAngle": {"field": "startAngle"},
  "endAngle": {"field": "endAngle"},
  "innerRadius": {"value": 20},
  "outerRadius": {"scale": "r", "field": "memory"},
  "stroke": {"value": "#fff"}
},
"update": {
  "fill": {"value": "#ccc"}
},
"hover": {
  "fill": {"value": "skyblue"}
}
  }
   },

{
 "type": "text",
 "from": {"data": "table"},
"encode": {
"enter": {
  "x": {"field": {"group": "width"}, "mult": 0.5},
  "y": {"field": {"group": "height"}, "mult": 0.5},
  "radius": {"scale": "r", "field": "memory", "offset": 8},
  "theta": {"signal": "(datum.startAngle + datum.endAngle)/2"},
  "fill": {"value": "#000"},
  "align": {"value": "center"},
  "baseline": {"value": "middle"},
  "text": {"field": "memory"}
 }
}
}
]     
  }
```

---

<div class="post-metadata">

**Author:** ![Bill\_McConaghy](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bill\_McConaghy](https://discuss.elastic.co/u/Bill_McConaghy)\
**Post date:** [August 6, 2018, 1:16pm UTC](https://discuss.elastic.co/t/how-to-access-nested-json-in-vega/140721/2 "2018-08-06T13:16:38Z")

</div>

Sorry for the delay in reply. I was able to get this to work by eliminating the duplicate key in your json (transform appears twice).

```
{
"$schema": "https://vega.github.io/schema/vega/v3.json",
"data": [
{
"name": "table",
"url": {

"%context%": "true",

 "index": "pie*",

 "body": {
  "size": "10"

 }
 },

"format": { "property": "hits.hits" },

"transform": [
 {
  "type": "formula",
  "expr": "toNumber(datum[\"_source\"][\"data\"][\"memory\"])",
  "as": "memory"
    },
    {"type": "pie", "field": "memory"}]
 }
      ],
  "scales": [
   {
 "name": "r",
  "type": "sqrt",
  "domain": {"data": "table", "field": "memory"},
 "zero": true,
 "range": [20, 100]
     }
   ],

 "marks": [
{
 "type": "arc",
  "from": {"data": "table"},
  "encode": {
   "enter": {
    "x": {"field": {"group": "width"}, "mult": 0.5},
  "y": {"field": {"group": "height"}, "mult": 0.5},
  "startAngle": {"field": "startAngle"},
  "endAngle": {"field": "endAngle"},
  "innerRadius": {"value": 20},
  "outerRadius": {"scale": "r", "field": "memory"},
  "stroke": {"value": "#fff"}
},
"update": {
  "fill": {"value": "#ccc"}
},
"hover": {
  "fill": {"value": "skyblue"}
}
  }
   },

{
 "type": "text",
 "from": {"data": "table"},
"encode": {
"enter": {
  "x": {"field": {"group": "width"}, "mult": 0.5},
  "y": {"field": {"group": "height"}, "mult": 0.5},
  "radius": {"scale": "r", "field": "memory", "offset": 8},
  "theta": {"signal": "(datum.startAngle + datum.endAngle)/2"},
  "fill": {"value": "#000"},
  "align": {"value": "center"},
  "baseline": {"value": "middle"},
  "text": {"field": "memory"}
 }
}
}
]     
  }
```

---

<div class="post-metadata">

**Author:** ![Narasimma\_varman](https://avatars.discourse-cdn.com/v4/letter/n/e56c9b/32.png) [@Narasimma\_varman](https://discuss.elastic.co/u/Narasimma_varman)\
**Post date:** [August 23, 2018, 7:53am UTC](https://discuss.elastic.co/t/how-to-access-nested-json-in-vega/140721/3 "2018-08-23T07:53:03Z")

</div>

thanks Bill\_McConaghy

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 20, 2018, 7:53am UTC](https://discuss.elastic.co/t/how-to-access-nested-json-in-vega/140721/4 "2018-09-20T07:53:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
