# Get value from JSON

**URL:** <https://forum.robotframework.org/t/get-value-from-json/6416>\
**Category:** Robot Framework\
**Created:** [31 October 2023 14:30 UTC](https://forum.robotframework.org/t/get-value-from-json/6416 "2023-10-31T14:30:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CrashTestDummy](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@CrashTestDummy](https://forum.robotframework.org/u/CrashTestDummy)\
**Post date:** [31 October 2023 14:30 UTC](https://forum.robotframework.org/t/get-value-from-json/6416/1 "2023-10-31T14:30:42Z")

</div>

How can I get a certain value out of JSON if I know one specific value. If I want to extract car type and I know the car name. I have try different variations of this: ${GetType}= Get Value From Json ${CarList.json()} $…type[?($.name=Focus)]

```python
[
  {
    "Manuafacture": "BMW",
    "Engine": [
      {
        "volume": 3,
        "filter": 222,
        "name": "Turbo-dd"
      }
    ],
    "name": "320",
    "type": "333-44-12"
  },
  {
    "Manuafacture": "Ford",
    "Engine": [
      {
        "volume": 2,
        "filters": 1111,
        "name": "doch"
      }
    ],
    "name": "Focus",
    "type": "444-55-33"
  },
  {
    "Manuafacture": "Audi",
    "Engine": [
      {
        "volume": 3,
        "filters": 444,
        "name": "TFSI"
      }
    ],
    "name": "A6",
    "type": "999-88-77"
  }
]

```

---

<div class="post-metadata">

**Author:** ![robinmackaij](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/robinmackaij/32/126_2.png) [@robinmackaij](https://forum.robotframework.org/u/robinmackaij)\
**Post date:** [5 November 2023 12:35 UTC](https://forum.robotframework.org/t/get-value-from-json/6416/2 "2023-11-05T12:35:25Z")

</div>

I think this is one of those situations where using Python is a good idea:

```python
import json

list_of_cars = json.load("path_to_your_file")

[car_type] = [car.get("type") for car in list_of_cars if car.get("name") == "Focus"]

```

This snippet can easily be turned into a keyword, if so desired.

---

<div class="post-metadata">

**Author:** ![patrio](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@patrio](https://forum.robotframework.org/u/patrio)\
**Post date:** [30 November 2023 09:51 UTC](https://forum.robotframework.org/t/get-value-from-json/6416/3 "2023-11-30T09:51:25Z")

</div>

Hi I had the same issue (I needed an ID of a form and knew only name of the form) and I solved it using JSONLibrary. I stored the JSON response into a variable which I converted into a dictionary and then used “get value from json” as you did.

I also noticed that you dont use quotation marks for the value of a key name=‘Focus’  
Exmaple of my JSON:

> ```
> {
> "total": 2,
> "data": [
> {
> "id": 80,
> "name": "22.11.",
> "description": "desc",
> "isPublished": true,
> "publishedAt": "2023-11-22T11:41:08.3630569",
> "publishedVersionId": 258,
> "lastVersionId": 258,
> "publishedVersion": 2,
> "lastVersion": 2
> },
> {
> "id": 83,
> "name": "28.11.",
> "description": "desc",
> "isPublished": false,
> "publishedAt": null,
> "publishedVersionId": null,
> "lastVersionId": 265,
> "publishedVersion": null,
> "lastVersion": 1
> }
> ]
> }
> 
> ```

Here is my code:

> ```
> ${responseGET}= GET https://xxxxx.com/api/form headers=${header}
> ${json} Set Variable ${responseGET.json()}
> Convert to Dictionary ${json}
> ${id} Get value from json ${json} $..data[?(@.name=='${formName}')].id
> 
> ```

Hope this helps 🙂
