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

JSON formatter: a duplicate key crashes the whole tool

Aperta
#218 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@lb1192176991-lab ci sta già lavorando.

Dal 20/10/2026.

  • #222 di @lb1192176991-lab — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
next.js, typescript

Direzione di ricerca

Start with lib/json-utils.ts, comparing the six llParse(raw) call sites with the existing error handling in format() and minify(). Add focused tests for toCSV, toTypeScript, toYAML, toXML, toQueryString, and sortKeys, then verify that the conversion panel remains on the page. Run npm run lint, npm run test, and npm run build; an open linked PR already exists for issue #222.

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

Descrizione

bug good first issue hacktoberfest

Paste this into the JSON formatter:

{"a": 1, "a": 2}

The whole tool is replaced by "This tool hit an unexpected error" (app/error.tsx).

validate() (lib/json-utils.ts, line 71) checks the input with JSON.parse, which accepts a duplicate key and keeps the last value. The conversions then parse the input again with lossless-json, which throws Duplicate key 'a' encountered at position 10. format() and minify() catch that and return it as an error (lines 91 to 95), but these six don't:

  • toCSV (line 137), toTypeScript (line 315), toYAML (line 422), toXML (line 580) and toQueryString (line 623)
  • sortKeys (line 503)

The conversion panel runs one of them while it renders (ConversionPanel.tsx, line 49, and TypeScript is the default mode), so the error reaches the error page. Sort keys throws from its click handler (JsonFormatterClient.tsx, line 109) instead of showing a message.

What to do

  • Catch the parse error in those six functions and return { ok: false, error: parseSyntaxError(raw, e) }, the way format() does. One small helper that all six call is fine.
  • The panel and Sort keys then show "Duplicate key 'a' encountered at position 10", like Format does, and the page stays up.

Where to look

  • lib/json-utils.ts: validate (line 71), format (line 86) and the six llParse(raw) calls above
  • app/(tools)/json-formatter/components/ConversionPanel.tsx: the useMemo at line 49
  • lib/__tests__/json-tree.test.ts renders a component with renderToStaticMarkup, if you also want a test for the panel

Acceptance criteria

  • With {"a": 1, "a": 2} in the editor, the page stays up, and the TypeScript, CSV, YAML, XML and Query string modes show the duplicate key error
  • Sort keys shows the same error
  • Tests: each of the six functions returns ok: false for a duplicate key (they throw on the current code)
  • npm run lint, npm run test and npm run build pass

Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off develop, and open your PR against develop with Closes #218 in the description.

Lingua principale
TypeScript
Stelle
1
Fork
9
Merge medio
10h 24m
PR unite (30g)
93

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 codercops/toolbelt

Tutte le issue di codercops/toolbelt

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.