Search code examples
jsongounmarshallingjmespath

What can be the issue for the following error: invalid character '-' after top-level value?


I am using the golang library go-jmespath to query a json file. My code looks like the following:

package main

import (
    "encoding/json"
    "log"

    "github.com/jmespath/go-jmespath"
)

func main() {
    var jsonBlob = []byte(`[
    {
        "oeeId": 3162396,
        "oeeDate": "2019-03-06T00:00:00",
        "oee": 21.2
    }]`)

    var d interface{}

    err := json.Unmarshal(jsonBlob, &d)
    if err != nil {
        log.Printf("1: %s", err)
    }

    res, err := jmespath.Search("{ labels: ['example'], datasets: [{label: 'Verfügbarkeit', data: [?oeeDate == `2019-03-06T00:00:00`].oee}]}", d)
    if err != nil {
        log.Printf("2: %s", err)
    }
    log.Println(res)
}

Here is also a link to an example in the Playground.

When I execute this code I get the following error:

invalid character '-' after top-level value

I am wondering what's my issue with this code since this example works with other Jmespath implementations like the javascript jmespath.js library.

The error seems to be in the query rather than the input data. Can anybody help me on this one?


Solution

  • Replacing the backticks in the search string with single quote removes the error.

    Use this instead: "{ labels: ['example'], datasets: [{label: 'Verfügbarkeit', data: [?oeeDate == '2019-03-06T00:00:00'].oee}]}".

    No more error.