XML to JSON Sergey Svistunov

Convert 1,000,000 person records from XML to JSON as fast as possible.

Input

XML document on STDIN:

<?xml version="1.0" encoding="UTF-8"?>
<persons>
    <person id="1512376">
        <age>30</age>
        <height>169.1</height>
        <married>true</married>
        <phone code="+6"><number>1283603279</number></phone>
        <phone code="+6"><number>1659964668</number></phone>
    </person>
    ...
</persons>

Output

One JSON object per person to STDOUT, preserving order:

{
    "id": 1512376,
    "age": 30,
    "height": 169.1,
    "married": true,
    "phones": [
        {
            "code": "+6",
            "number": 1283603279
        },
        {
            "code": "+6",
            "number": 1659964668
        }
    ]
}

Constraints

  • Preserve the order of persons
  • Omit the phones field if the phone array is empty
  • Maximum number of phones per person is 3
Back to listMay 5, 2026 07:48Victor MerckléVictor MerckléError
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 5, 2026 07:49017,659,87702,343,0002,514,944diff:   any( -  map[string]any{ -  "height": s"188.7", -  "id": s"369311", -  "married": bool(false), -  "phones": []any{ -  map[string]any{"code": string("+2"), "number": s"1912755032"}, -  map[string]any{"code": string("+1"), "...stderr
2May 5, 2026 07:49018,592,99602,320,0002,523,136diff:   any( -  map[string]any{ -  "age": s"27", -  "height": s"199.5", -  "id": s"141594", -  "married": bool(false), -  "phones": []any{ -  map[string]any{"code": string("+2"), "number": s"1792726505"}, -  map[string]any{...stderr
3May 5, 2026 07:49019,363,54302,333,0002,527,232diff:   any( -  map[string]any{"height": s"179.8", "id": s"506837", "married": bool(false)}, +  s"0",   ) stderr