itchyny / gojq

Pure Go implementation of jq
MIT License
3.3k stars 119 forks source link

Using "/" in a string constant #259

Closed tyler-c-jones closed 3 months ago

tyler-c-jones commented 3 months ago

I'm hoping to be able to pass a string constant such as "/health/labs" as an expression. However this fails with unexpected token "/". We are using gojq as a way to parse various expressions - in this case a path for an url destination in an email template. We may also pass another expression - in this instance it is a constant.

This should be valid jq. Here is a sample from jqplay. Note that we are using this in a Go service, not from the CLI. We have attempted both ways of escaping this string in Go (backticks and escaping like //).

itchyny commented 3 months ago

I don't understand. Following code works.

package main

import (
    "fmt"
    "log"

    "github.com/itchyny/gojq"
)

func main() {
    query, err := gojq.Parse(`"/health/labs"`)
    if err != nil {
        log.Fatalln(err)
    }
    iter := query.Run(nil)
    for {
        v, ok := iter.Next()
        if !ok {
            break
        }
        if err, ok := v.(error); ok {
            log.Fatalln(err)
        }
        fmt.Printf("%#v\n", v)
    }
}
tyler-c-jones commented 3 months ago

oh its because I'm a dummy, and the " were not in place as they should be. appreciate the response!