# Use range and where in JSON data files

**URL:** https://discourse.gohugo.io/t/use-range-and-where-in-json-data-files/18254
**Category:** support
**Created:** [April 22, 2019, 9:26pm UTC](https://discourse.gohugo.io/t/use-range-and-where-in-json-data-files/18254 "2019-04-22T21:26:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![solopx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/solopx/32/8218_2.png) [@solopx](https://discourse.gohugo.io/u/solopx)
#### Post date: [April 22, 2019, 9:26pm UTC](https://discourse.gohugo.io/t/use-range-and-where-in-json-data-files/18254/1 "2019-04-22T21:26:52Z")

</div>

I have this JSON data file - see example:

```auto
       [
	{
		"date": "2019-4-22_16-21",
		"site": "https://www.bnbc.com/",
		"link": "https://www.bnbc.com/sites/"
	},
	{
		"date": "2019-4-22_16-21",
		"site": "https://www.wdc.com/new/",
		"link": "https://www.wdc.com/new-sites/"
	},
	{
		"date": "2019-4-23_18-22",
		"site": "https://www.bnbc.com/new/",
		"link": "https://www.bnbc.com/new-sites/"
	}
]

```

1. I try to go first to find the items with a certain date (date = 2019-4-22\_16-21)

```auto
    {{ $json := getJSON "data/snippets.json" }}

    {{ $mydate := (where $json "date" .Params.date) }}

```

which is fine

1. Then I go to check the link to have in it “bnbc”

```auto
    {{ $bnbc := (where $mydate "link" "in" "bnbc") }}

```

On the second step unfortunately the range is empty, can you tell me why?

---

<div class="post-metadata">

### Author: ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)
#### Post date: [April 23, 2019, 4:26am UTC](https://discourse.gohugo.io/t/use-range-and-where-in-json-data-files/18254/2 "2019-04-23T04:26:39Z")

</div>

From the docs on `where`: [collections.Where | Hugo](https://gohugo.io/functions/where/)

> ## Syntax
> 
> `where COLLECTION KEY [OPERATOR] MATCH`

> **`in`**
> 
> `true` if a given field value is included in a matching value; a matching value must be an array or a slice

So your snippet is testing if the `link` field value is contained in `"bnbc"`. What I _think_ you want is the reverse: test if `"bnbc"` is contained in the value of the `link` field.

I don’t think you can do that inside a `where`.

```auto
{{ $bnbc := slice }}
{{ range $mydate }}
  {{ if in .link "bnbc" }}
    {{ $bnbc = $bnbc | append . }}
  {{ end }}
{{ end }}

```

---

<div class="post-metadata">

### Author: ![solopx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/solopx/32/8218_2.png) [@solopx](https://discourse.gohugo.io/u/solopx)
#### Post date: [April 23, 2019, 6:55am UTC](https://discourse.gohugo.io/t/use-range-and-where-in-json-data-files/18254/3 "2019-04-23T06:55:24Z")

</div>

Thank you … that works now
