Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Replacing specific array item

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
json, powershell
Ambito
tooling

Direzione di ricerca

Inizia dalla pagina wiki Replace e riproduci Sample transform 1 sul JSON fornito, quindi confrontalo con la root-level transform funzionante. Traccia come viene analizzato e applicato un @jdt.path relativo a un array; il lavoro è completato quando il Value dell'elemento Foo cambia senza dipendere dalla sua posizione ordinale.

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

Descrizione

I am having trouble replacing specific array items using the @jdt.path syntax as described on the "Replace" wiki page. The @jdt verbs and attributes don't parse or transform when placed under the array object itself. I was able to get this working by moving the @jdt.replace to the top of the object and then drilling down. Is this a bug?

Sample JSON:

{
  "MyStuff": [
    {
      "Name": "Foo",
      "Value": 123
    },
    {
      "Name": "Bar",
      "Value": 456
    }
  ]
}

The goal is to change the value of the "Foo" item without knowing the ordinal position or how many objects are in the MyStuff array.

Sample transform 1:

{
  "MyStuff": {
    "@jdt.replace": {
      "@jdt.path": "@[?(@.Name == 'Foo')].Value",
      "@jdt.value": 456
    }
  }
}

This should work according to the documentation but all I get is the MyStuff node literally replaced with the transform syntax.

Sample transform 2:

{
  "@jdt.replace": {
    "@jdt.path": "$.MyStuff[?(@.Name == 'Foo')].Value",
    "@jdt.value": 456
  }
}

Alternately, if we place the @jdt.replace at the root and change @jdt.path to start from the root and navigate into MyStuff, it works as expected.

I'm using Visual Studio 2022 + SlowCheetah 4.0.50 in a .NET Framework 4.7.2 project.

Lingua principale
PowerShell
Stelle
115
Fork
39
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

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 microsoft/json-document-transforms

Tutte le issue di microsoft/json-document-transforms

Issue simili

Altre issue su DevTools

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.