Skip to content

clean8s/peekcty

Repository files navigation

JSONPath for go-cty: peekcty

Go Test Go Reference

peekcty lets you iterate over cty datastructures using JSONPath syntax.

Note: go-cty is the serialization / typesystem library for Go powering HCL, Terraform, zclconf.

Example

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")}

Implementation

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 of reflect.Value

You can use all features except for filters:

  • $[0, 1]
  • $.field
  • $.wildcard[*]
  • $.x.y..recursive
  • m[1:], slice2[:2], slice3[1:5]

LICENSE

Licensed under MIT.

This is an extension not officially affiliated with the cty library by Martin Atkins.

About

Data type validation/serialization library for Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages