I
I
ivandao2019-07-17 14:12:33
JavaScript
ivandao, 2019-07-17 14:12:33

How to make a jsonpath request?

var cities = [
  { name: "London", "population": 8615246 },
  { name: "Berlin", "population": 3517424 },
  { name: "Madrid", "population": 3165235 },
  { name: "Rome",   "population": 2870528 }
];

var jp = jsonpath; //  для краткости
var names = jp.query(cities, '$..name');
console.log(names); // [ "London", "Berlin", "Madrid", "Rome" ]

How to get the name of a city whose population is 2870528?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2019-07-17
@ivandao

$[?(@.population == 2870528)].name
You can try at jsonpath.com
See query language . Filter?( условие )

A
alekssamos, 2019-07-17
@alekssamos

Could it be something like this?'["population"=2870528]'

R
Roman Fov, 2019-07-17
@Roman-Fov

json

{
  "cities": [
      { "name": "London", "population": 8615246 },
      { "name": "Berlin", "population": 3517424 },
      { "name": "Madrid", "population": 3165235 },
      { "name": "Rome",   "population": 2870528 }
  ]
}

Query
Results
[
  {
    "name": "London",
    "population": 8615246
  }
]

It?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question