question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to access nested json in vega

See original GitHub issue

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 } } }

`

Home / Community Help / 

Your question was successfully posted! avatar image How to access nested json in vega Question by Narasimma varman 21 secs ago elasticsearchkibanalogstash

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"}
 }
}
}
]     
  }`

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mattijncommented, Jul 19, 2018

You’ve defined a "format": { "property": "hits.hits" } in your data variable, which I don’t see in your data. Even if it was, in my understanding property doesn’t accept double nested parameters (eg. varx.vary), but for that I might be wrong.

Next you have two transform definitions in a single data specification.

Changing this, gives me: pokp

Click to expand

{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "data": [
    {
      "name": "table",
      "values": [
        {
          "_index": "pie",
          "_type": "flare",
          "_id": "2",
          "_version": 1,
          "_score": 1,
          "_source": {"id": 2, "parent": 1, "data": {"memory": 50}}
        }
      ],
      "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"}
        }
      }
    }
  ]
}
1reaction
mattijncommented, Jul 22, 2018

You could use flatten(docs), which maps array-valued fields to a set of individual data objects. In combination with project (docs), it is possible to place nested fields on a higher level towards.

"transform": [
  {
    "type": "flatten",
    "fields": ["_source.data"],
    "as": ["data"]
  },
  {
    "type": "project",
    "fields": ["data.memory.value"],
    "as": ["memory"]
  },
  {"type": "pie", "field": "memory"}       
]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Vega: Access nested fields of a JSON file - Elastic Discuss
How can I access the Status and ID fields in a Vega code? I tried doing it like below without any success. "format":...
Read more >
How to access nested json in vega - kibana - Stack Overflow
I am using vega in kibana. I try to access nested json field but I cannot able to access that field, could anyone...
Read more >
Nested Bar Chart Example - Vega & Vega-Lite
This nested bar chart depicts aggregated values across multiple categories. The input data is subdivided according to two fields (with uneven category ...
Read more >
Handeling Nested Json files - Designer - Alteryx Community
Solved: I''m building a workflow that contains json data. this data is ... can this be done with the json parse tool or...
Read more >
How To Create a Visualization for Nested Objects Templates?
A Vega specification defines an interactive visualization in a JSON format. ... you should use the nested datatype instead of the object datatype....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found