Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

JSON to XML: keys like `@type`, `$ref` or `bad key` turn into `<item>`

Abierto
#214 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@AyanZahid-Code ya está trabajando en esto.

Desde el 20/10/2026.

  • #216 de @AyanZahid-Code — cerrado sin fusionar
  • #217 de @AyanZahid-Code — cerrado sin fusionar

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
json, typescript, xml
Área
tooling

Línea de trabajo

Start with sanitizeTag and its callers in lib/json-utils.ts, then extend the toXML tests beginning at line 113 in lib/__tests__/json-utils.test.ts. Implement the specified ASCII tag-name rules and verify scalar keys, arrays, empty keys, Unicode, and unchanged valid names without adding an XML parser. Run npm run lint, npm run test, and npm run build; all should pass. Note that linked pull requests 216 and 217 are closed and unmerged, so confirm the issue remains unclaimed before starting.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug good first issue hacktoberfest

The JSON formatter's XML conversion (toXML in lib/json-utils.ts) writes each key as a tag name. When a key isn't a valid XML name, sanitizeTag (line 573) drops the whole key and writes item instead:

{"bad key": 1, "1x": 2, "@type": "Person", "$ref": "#/a"}

gives

<root>
  <item>1</item>
  <item>2</item>
  <item>Person</item>
  <item>#/a</item>
</root>

so there's no way to tell which value was which. It happens to keys with a space or a leading digit, and to the @ and $ keys that JSON-LD (@context, @type, @id) and JSON Schema ($schema, $ref) use all the time. An array under such a key loses its name too: {"my tags": ["a", "b"]} gives two <itemItem> elements.

What to do

Keep the key and change only what XML doesn't allow:

  • replace every character that isn't an ASCII letter, digit, _, - or . with _
  • put _ in front if the result starts with a digit, - or .
  • an empty key stays item

So bad key becomes bad_key, 1x becomes _1x, @type becomes _type, $ref becomes _ref and a:b becomes a_b. Keys that are fine today, like first-name, user.id and _id, don't change.

Stay with ASCII, even though XML allows many other letters in names. Parsers don't agree on which ones (Python's built-in parser rejects some that libxml2 accepts), and ASCII names work in all of them. So café becomes caf_. Today it becomes item.

Where to look

  • lib/json-utils.ts: sanitizeTag (line 573). toXML uses it for keys (line 609), array items (line 591) and the root element (line 615), so array items follow the fixed name without extra work: {"my tags": ["a", "b"]} should give two <my_tag> elements.
  • lib/__tests__/json-utils.test.ts: the toXML tests start at line 113

Acceptance criteria

  • bad key, 1x, @type, $ref, a:b and -a give <bad_key>, <_1x>, <_type>, <_ref>, <a_b> and <_-a>
  • first-name, user.id and _id don't change, an empty key gives <item>, and café gives <caf_>
  • {"my tags": ["a", "b"]} gives two <my_tag> elements
  • Tests check the output text for each case above (please don't add an XML parser as a dependency)
  • 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 #214 in the description.

Lenguaje dominante
TypeScript
Estrellas
1
Forks
9
Merge medio
10 h 24 min
PR fusionados (30 d)
93

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de codercops/toolbelt

Todos los issues de codercops/toolbelt

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.