I’m using getJSON
to read a local file. I’m hoping to filter the array of json objects.
programs
is a key on each of the objects in the array returned by getJSON. I’d like to make sure that the words ‘Gulf Restoration’ are included anywhere in the programs
field which is a string that can contain multiple program names separated by a space or a comma.
Example JSON object
{
office: "",
name: "Roles relating to funds from the Deepwater Horizon Oil Spill",
type: "Fact Sheet",
url: "fact-sheet/roles-relating-to-funds-from-the-deepwater-horizon-oil-spill.pdf",
year: "2017",
programs: "Gulf Restoration, National Wildlife Refuge System",
keywords: "",
state: "",
}
Attempted template
{{ $data := getJSON "../dist/data/reading-room-documents.js" }}
{{ range where $data "programs" "in" "Gulf Restoration" }}
<!-- this seems to return EVERY object from the array rather than filtering -->
{{ end }}
This works if I substitute the “eq” operator instead, but the value from the programs
key is a string that can contain multiple program names so I want to use in
rather than eq
.
{{ $data := getJSON "../dist/data/reading-room-documents.js" }}
{{ range where $data "programs" "eq" "Gulf Restoration" }}
<!-- this works if and only if the value of the programs key has 'Gulf Restoration as a value -->
{{ end }}