What possible problem could cause the error: an invalid character '-' appearing after a top-level value?

Utilizing the go-jmespath Golang library for querying a json file, my code is structured as follows:

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

Check out this example on the Playground.

When running this code, an error message stating "invalid character '-' after top-level value" is encountered.

I am puzzled about the issue in my code, especially since similar Jmespath implementations like the javascript jmespath.js library work fine with this example.

The problem appears to be in the query itself rather than the input data. Any insights or assistance would be greatly appreciated!

Answer №1

To eliminate the error, simply swap out the backticks in the search query with single quotes.

Replace it with:

"{ labels: ['example'], datasets: [{label: 'Availability', data: [?oeeDate == '2019-03-06T00:00:00'].oee}]}"
.

The error is now resolved.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The synopsis cannot be displayed by the RottenTomatoes API

I'm having some trouble with the RottenTomatoes movies API. I've been trying to display the movie's synopsis below the input field, but it's not working as expected. Can anyone point out what might be causing the issue here? If you nee ...

Utilizing SparkSQL to load JSON data into MongoDB

I'm looking to import a JSON file into MongoDB using Spark SQL. Currently, I have a process for loading individual elements into a collection as shown below: val mongoClient = MongoClient(127.0.0.1, 27017) val collection = mongoClient(dbname)(collect ...

Decode JSON with an integer as the key

Alright, so here's the situation. I've got this massive JSON feed and everything is running smoothly. However, there's just one small hiccup Currently, my approach involves: $json=file_get_contents($source); $data = json_decode($json,true) ...

Error unfound: [CLIENT_MISSING_INTENTS]: The Client requires valid intents to function properly

I've gone through multiple tutorials, but I keep encountering an uncaught TypeError. Despite following the suggested solutions, the error persists. I even tried implementing the "intent" solution, but it's prompting a change in "const client = ne ...

Incorporate a refresh button into the JSON table view that includes an activity

How can I implement a refresh button in my app that displays an activity indicator when pressed? I have written the following code: In this app, I am using JSON to retrieve data from a server and I want users to see updated content when they press the re ...

What is the proper way to generate an iframe with a width set to "100%" or left empty, rather than width = "100"?

I am currently utilizing vimeowrap to iterate through a playlist of videos. I would like the iframe that is generated by vimeowrap to have either a width and height set to "100%" or nothing at all. For more information on Vimeo Wrap, visit: To see my tes ...

Executing a Javascript function within a PHP script

I am trying to retrieve JSON data from a JavaScript function and use it as a variable in PHP. Here is the function I have: <script type="text/javascript" src="Scripts/jquery-1.9.1.min.js"></script> <script> $(fu ...

A guide on showing POST values from javascript XMLHttpRequest() in php

I have encountered an issue where I am using the XMLHttpRequest() javascript function to send parameters in Json format to another php page, but for some reason $_POST['appoverGUID'] is not receiving the posted values. Below is my Javascript cod ...

Uncovering targeted terms within JSON structures with Python

I have developed an automation script to extract information from a word document and convert it into a JSON object. However, I am facing difficulty in retrieving specific values, particularly the applied voltage values of each test case, and storing them ...

Angular2: The NgFor directive is designed to work with Iterables like Arrays for data binding

I'm currently working on a university project to develop a web application consisting of a Web API and a Frontend that interacts with the API. The specific focus of this project is a recipe website. Although I have limited experience with technologies ...

What is the best way to change a java.lang.String object into a java.util.LinkedHashMap in

After successfully converting java.lang.String to or.simple.json.JSONObject, I encountered an issue when trying to cast it to a HashMap. org.json.JSONObject jso = new org.json.JSONObject("{"phonetype":"N95","cat":"WP"}"); LinkedHashMap h = (Linked ...

[AWS Lambda SDK] - Executing Lambda Function - Processing Payload Response as Unit8Array - Conversion to String

Currently, I am utilizing the npm package @aws-sdk/client-lambda to invoke Lambdas. In my setup, I have two Lambdas - Lambda A and Lambda B, with Lambda A responsible for invoking Lambda B. The invocation of Lambda B from Lambda A is done through the foll ...

An efficient method for extracting data from a JSON array and integrating it into a DataTables display

I am struggling to populate data tables with values from a PHP file that returns JSON responses. Despite receiving the JSON response, I am unable to successfully append the data to the data table. Below is the code snippet used for generating the JSON resp ...

Sandwich Bot using MS Bot Framework displaying JSON in Command Prompt

Currently, I am using the Microsoft Bot Framework and diligently following their guide (utilizing C# for the .NET version) to construct a Simple Sandwich Bot The initial stages of setting up the bot have been successful. However, upon interacting with the ...

Changing an Array into JSON format using AngularJS

I am attempting to switch from a dropdown to a multiselect dropdown. <select name="molecularMethod" class="form-control" ng-model="request.molecularMethod" multiple> It is functioning properly. However, when items are selected, it generates an arra ...

Retrieving a Large Amount of JSON Data from the Server

Within my jQueryMobile and PhoneGap project, I have over 1000 data entries in JSON format. My main challenge is the need to retrieve all this data as quickly as possible. To achieve this, I am currently implementing a method of fetching data during the Sc ...

How to prevent ConcurrentModificationException while converting to Json format?

In our project, we have a custom class called Document that utilizes a private member of type Map<String, Object> to store data. These objects are stored in memory and often modified by multiple threads. Additionally, these objects, particularly the ...

Converting JSON data into an HTML table

I'm struggling to convert a JSON object into an HTML table, but I can't seem to nail the format. DESIRED TABLE FORMAT: Last Year This Year Future Years 45423 36721 873409 CURRENT TABLE FORMAT: Last Year 45423 This ...

"Encountered a problem while trying to insert data using JSON and Ajax

I've been struggling to figure out where the issue lies in my code. I've double-checked everything and it all seems correct, but I keep encountering errors. Below is the code snippet: Markup: <link href="http://ajax.googleapis.com/ajax/libs ...

Steps to upload an image using an API

I am attempting to use an API to upload a file to imgBB, but I encountered the following error message: {"status_code":400,"error":{"message":"Empty upload source.","code":130},"status_txt":&q ...