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 listOct 14, 2026 03:45Karthik ReddyKarthik ReddyScore: 3,562Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Oct 14, 2026 03:503,54441,263,67123,631,0008,628,00093,110,272
2Oct 14, 2026 03:503,54742,818,52123,679,0008,602,00093,114,368
3Oct 14, 2026 03:503,55041,308,42023,702,0008,610,00093,077,504
4Oct 14, 2026 03:503,55641,356,01323,755,0008,608,00093,097,984
5Oct 14, 2026 03:503,56241,483,75923,757,0008,666,00093,196,288
6Oct 14, 2026 03:503,56541,376,14923,787,0008,660,00093,184,000
7Oct 14, 2026 03:503,58141,569,54723,849,0008,741,00093,143,040
8Oct 14, 2026 03:503,58341,559,58223,873,0008,733,00093,110,272
9Oct 14, 2026 03:503,58641,647,72223,891,0008,749,00093,138,944