# How to check if a key exists within a JSON file

**URL:** https://discourse.processing.org/t/how-to-check-if-a-key-exists-within-a-json-file/34214
**Category:** Coding Questions
**Created:** [December 20, 2021, 11:12pm UTC](https://discourse.processing.org/t/how-to-check-if-a-key-exists-within-a-json-file/34214 "2021-12-20T23:12:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ybr](https://avatars.discourse-cdn.com/v4/letter/y/df788c/32.png) [@ybr](https://discourse.processing.org/u/ybr)
#### Post date: [December 20, 2021, 11:12pm UTC](https://discourse.processing.org/t/how-to-check-if-a-key-exists-within-a-json-file/34214/1 "2021-12-20T23:12:46Z")

</div>

Hi, I’m importing a JSON file using an API. For most elements within the array the key “rating” exists, for some it doesn’t. At that point my code stops with a null pointer exception. I’m trying to do a check whether a key exists, in other languages I learned about the .has() function but that doesn’t seem to work here. Any idea how I could do that within the Processing environment?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 20, 2021, 11:20pm UTC](https://discourse.processing.org/t/how-to-check-if-a-key-exists-within-a-json-file/34214/2 "2021-12-20T23:20:51Z")

</div>

Can you check  
myVar==null

or != null?
