{"id":19470319,"url":"https://github.com/kesin11/ts-junit2json","last_synced_at":"2025-04-25T12:30:49.842Z","repository":{"id":39583694,"uuid":"234563870","full_name":"Kesin11/ts-junit2json","owner":"Kesin11","description":"Convert JUnit XML format to JSON with TypeScript","archived":false,"fork":false,"pushed_at":"2025-04-11T19:43:58.000Z","size":1309,"stargazers_count":12,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T18:25:34.593Z","etag":null,"topics":["bigquery","junit-xml"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kesin11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-17T14:22:43.000Z","updated_at":"2025-04-11T19:44:01.000Z","dependencies_parsed_at":"2022-09-04T09:50:43.273Z","dependency_job_id":"6267c45c-9f85-4605-8b7e-2f41ef483395","html_url":"https://github.com/Kesin11/ts-junit2json","commit_stats":{"total_commits":290,"total_committers":6,"mean_commits":"48.333333333333336","dds":0.6241379310344828,"last_synced_commit":"e6e7e3cb452687adda8e2f01fb0b28088e265946"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kesin11%2Fts-junit2json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kesin11%2Fts-junit2json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kesin11%2Fts-junit2json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kesin11%2Fts-junit2json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kesin11","download_url":"https://codeload.github.com/Kesin11/ts-junit2json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250817535,"owners_count":21492168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bigquery","junit-xml"],"created_at":"2024-11-10T18:57:25.115Z","updated_at":"2025-04-25T12:30:49.526Z","avatar_url":"https://github.com/Kesin11.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-junit2json\n[![junit2json](https://badgen.net/npm/v/junit2json)](https://www.npmjs.com/package/junit2json)\n[![JSR](https://jsr.io/badges/@kesin11/junit2json)](https://jsr.io/@kesin11/junit2json)\n![CI](https://github.com/Kesin11/ts-junit2json/workflows/Node%20CI/badge.svg)\n\nts-juni2json provides a converter that convert JUnit XML format to JSON. Also provides TypeScript types definition.\n\nAnd also provide [CLI](#CLI) that can convert a JUnit XML to JSON.\n\n# Purpose\nts-junit2json is created for uploading test result data to BigQuery.\n\nMany languages and test frameworks supporting output test result data as JUnit XML format that de fact standard in today. On the other hand, BigQuery does not support to import XML but does support JSON.\n\nYou notice that you can upload test data to BigQuery with converting XML to JSON. ts-junit2json provides a simple JUnit XML to JSON converter for that purpose.\n\n# What is difference for other XML to JSON tools?\nThe purpose of other similar tools is handling common XML format. As a result, output JSON structure is sometimes redundant and not suitable for store in BigQuery.\n\nOn the other hand, ts-junit2json only supports JUnit XML schema, but restructures original XML structure into a BigQuery friendly structure. Details are described below.\n\n# Installing\n```bash\nnpm install junit2json\n```\n\n# Usage\n## Node.js\njunit2json supports both ESModule and CommonJS.\n\n```ts\nimport { parse } from 'junit2json' // ESM\n// const { parse } = require('junit2json') // CommonJS\n\nconst main = async () =\u003e {\n  const xmlString = `\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n  \u003ctestsuites name=\"gcf_junit_xml_to_bq_dummy\" tests=\"2\" failures=\"1\" time=\"1.506\"\u003e\n    \u003ctestsuite name=\"__tests__/basic.test.ts\" errors=\"0\" failures=\"0\" skipped=\"0\" timestamp=\"2020-01-26T13:45:02\" time=\"1.019\" tests=\"1\"\u003e\n      \u003ctestcase classname=\"convert xml2js output basic\" name=\"convert xml2js output basic\" time=\"0.01\"\u003e\n      \u003c/testcase\u003e\n    \u003c/testsuite\u003e\n    \u003ctestsuite name=\"__tests__/snapshot.test.ts\" errors=\"0\" failures=\"1\" skipped=\"0\" timestamp=\"2020-01-26T13:45:02\" time=\"1.105\" tests=\"1\"\u003e\n      \u003ctestcase classname=\"parse snapshot nunit failure xml\" name=\"parse snapshot nunit failure xml\" time=\"0.013\"\u003e\n        \u003cfailure\u003eError: Something wrong.\u003c/failure\u003e\n      \u003c/testcase\u003e\n    \u003c/testsuite\u003e\n  \u003c/testsuites\u003e\n  `\n\n  const output = await parse(xmlString)\n  console.log(JSON.stringify(output, null, 2))\n}\nmain()\n```\n\n## Deno\njunit2json also published to jsr.io as `@kesin11/junit2json`.\nIf you using Deno, you can import from jsr as below.\n\n```ts\nimport { parse } from \"jsr:@kesin11/junit2json\";\n```\n\n# Output sample\n```json\n{\n  \"name\": \"gcf_junit_xml_to_bq_dummy\",\n  \"tests\": 2,\n  \"failures\": 1,\n  \"time\": 1.506,\n  \"testsuite\": [\n    {\n      \"name\": \"__tests__/basic.test.ts\",\n      \"errors\": 0,\n      \"failures\": 0,\n      \"skipped\": 0,\n      \"timestamp\": \"2020-01-26T13:45:02\",\n      \"time\": 1.019,\n      \"tests\": 1,\n      \"testcase\": [\n        {\n          \"classname\": \"convert xml2js output basic\",\n          \"name\": \"convert xml2js output basic\",\n          \"time\": 0.01\n        }\n      ]\n    },\n    {\n      \"name\": \"__tests__/snapshot.test.ts\",\n      \"errors\": 0,\n      \"failures\": 1,\n      \"skipped\": 0,\n      \"timestamp\": \"2020-01-26T13:45:02\",\n      \"time\": 1.105,\n      \"tests\": 1,\n      \"testcase\": [\n        {\n          \"classname\": \"parse snapshot nunit failure xml\",\n          \"name\": \"parse snapshot nunit failure xml\",\n          \"time\": 0.013,\n          \"failure\": [\n            {\n              \"inner\": \"Error: Something wrong.\"\n            }\n          ]\n        }\n      ]\n    }\n  ]\n}\n```\n\n# Filter some tags\nIf you want to filter some tags like `\u003csystem-out\u003e` or `\u003csystem-err\u003e`, you can use `replacer` function argument in [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).\n\n```ts\nconst output = await parse(xmlString)\nconst replacer = (key: any, value: any) =\u003e {\n  if (key === 'system-out' || key === 'system-err') return undefined\n  return value\n}\nconsole.log(JSON.stringify(output, replacer, 2))\n```\n\n# Notice\nts-junit2json changes the structure of some tags for simpler and more consistent output.\n\n- XML Tag inner text is set to value of 'inner' key.\n  - The only exceptions are `\u003csystem-out\u003e` and `\u003csystem-err\u003e`. These inner text is set to the string array.\n  - Example: [snapshot.test.ts.snap](./__tests__/__snapshots__/snapshot.test.ts.snap)\n\n# CLI\n```bash\nnpx junit2json junit.xml\n\n# with full options\nnpx junit2json -p -f system-out,system-err junit.xml\n```\n\n```\njunit2json \u003cpath\u003e\n\nConvert JUnit XML format to JSON\n\nPositionals:\n  path  JUnit XML path                                                  [string]\n\nOptions:\n  --help             Show help                                         [boolean]\n  --version          Show version number                               [boolean]\n  -p, --pretty       Output pretty JSON                                [boolean]\n  -f, --filter-tags  Filter XML tag names                               [string]\n\nExamples:\n  junit2json -p -f system-out,system-err    Output pretty JSON with filter\n  junit.xml                                 \u003csystem-out\u003e and \u003csystem-err\u003e tags.\n```\n\n## CLI with `jq` examples\n### Count testcases\n\n```bash\nnpx junit2json junit.xml | jq .tests\n```\n\n### Show testsuite names\n\n```bash\nnpx junit2json junit.xml | jq .testsuite[].name\n```\n\n### Show testcase classnames\n\n```bash\nnpx junit2json junit.xml | jq .testsuite[].testcase[].classname\n```\n\n# References\nJUnit XML format\n\n- https://llg.cubic.org/docs/junit/\n- https://github.com/junit-team/junit5/blob/main/platform-tests/src/test/resources/jenkins-junit.xsd\n\n# API reference\nhttps://jsr.io/@kesin11/junit2json/doc\n\n# License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkesin11%2Fts-junit2json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkesin11%2Fts-junit2json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkesin11%2Fts-junit2json/lists"}