Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

クローズ
#214 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@AyanZahid-Code がすでに取り組んでいます。

2026年10月20日 から。

  • #216 @AyanZahid-Code による — マージされずにクローズ
  • #217 @AyanZahid-Code による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
json, typescript, xml
領域
tooling

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
1
フォーク
9
平均マージ
7時間 34分
マージ済み PR(30日)
146

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

codercops/toolbelt のほかの issue

codercops/toolbelt の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。