peekcty lets you iterate over cty
datastructures using JSONPath syntax.
Note: go-cty is the serialization / typesystem library for Go powering HCL, Terraform, zclconf.
Given text_fixture_cars.json
:
import "github.com/clean8s/peekcty"
func demo() {
p, err := peekcty.NewPath("$..has")
fmt.Println(p.Search(carExample))
}
Prints:
".carOwners.A.has" => []{StringVal("Honda Accord"), StringVal("VW Up"), StringVal("Porsche 911")}
".carOwners.B.has" => []{StringVal("Renault Clio"), StringVal("Jaguar F-Type"), StringVal("Dodge Viper")}
".cars[0].has" => []{StringVal("4 doors")}
It's based on Kubernetes/kubectl
's implementation
here.
With two differences:
- it doesn't require templates or
range
blocks - it operates on
cty.Value
instead ofreflect.Value
You can use all features except for filters:
$[0, 1]
$.field
$.wildcard[*]
$.x.y..recursive
m[1:]
,slice2[:2]
,slice3[1:5]
Licensed under MIT.
This is an extension not officially affiliated with the cty
library by Martin Atkins.