Probable bug: mysterious nulls from wildcard expression

Aperta
#84 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@SAY-5 ci sta già lavorando.

Dal 12/5/2026.

  • #100 di @SAY-5 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go
Ambito
tooling

Direzione di ricerca

Riproduci il problema con il programma Go riportato e interroga "*.to_string(@)" sull’oggetto JSON fornito. Confronta il risultato con l’output JavaScript JMESPath; il lavoro è completato quando l’implementazione Go non aggiunge più stringhe "null" impreviste, mantenendo al contempo i valori dell’oggetto convertiti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I ran this program:

package main

import (
	"encoding/json"
	"fmt"

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

func main() {
	jsonBytes := []byte(`
		{
		   "author": "Mark Twain",
		   "title": "The Adventures of Tom Sawyer",
		   "words": 80000,
		   "year": 1876
		}
	`)
	var jsonData any
	err := json.Unmarshal(jsonBytes, &jsonData)
	if err != nil {
		panic(err)
	}

	queryResult, err := jmespath.Search("*.to_string(@)", jsonData)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%#v\n", queryResult)
}

Its output was:

[]interface {}{"null", "null", "null", "null", "Mark Twain", "The Adventures of Tom Sawyer", "80000", "1876"}

I don't understand where the "null" strings are coming from. This behaviour looks like a bug to me.

Here are go.mod and go.sum:

module bug-report

go 1.20

require github.com/jmespath/go-jmespath v0.4.0
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

Comparison with JavaScript

I ran these commands:

npm install [email protected]
./node_modules/jmespath/jp.js '*.to_string(@)' < book.json

Here is book.json:

{
   "author": "Mark Twain",
   "title": "The Adventures of Tom Sawyer",
   "words": 80000,
   "year": 1876
}

The output of the second command was:

["Mark Twain","The Adventures of Tom Sawyer","80000","1876"]

This is the output I expect to see from that JSON and that JMESPath query. It's obviously different from the output of the Go program.

Lingua principale
Go
Stelle
623
Fork
105
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jmespath/go-jmespath

Tutte le issue di jmespath/go-jmespath

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.