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 listApr 21, 2026 09:38limanjun99limanjun99Error
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2026 09:40012,434,8942,283,0002,283,0006,250,496diff: map[string]any{ "age": s"42", "height": s"163.1", - "id": s"949210", + "id": s"49210", "married": bool(true), "phones": []any{map[string]any{"code": string("+6"), "number": s"1271994791"}}, }
2Apr 21, 2026 09:40064,576,38225,348,00010,139,00092,676,096diff: map[string]any{ "age": s"19", "height": s"185.4", - "id": s"592669", + "id": s"92669", "married": bool(true), "phones": []any{map[string]any{"code": string("+9"), "number": s"1730178351"}}, }
3Apr 21, 2026 09:40059,267,68026,040,0009,013,00092,459,008diff: map[string]any{ "age": s"20", "height": s"178.5", - "id": s"73401", + "id": s"3401", "married": bool(false), "phones": []any{map[string]any{"code": string("+1"), "number": s"1555616260"}}, }