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 00:48Karthik ReddyKarthik ReddyScore: 3,902Success
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 00:533,89244,269,21026,944,0008,478,00092,852,224
2Oct 14, 2026 00:533,89444,425,75926,954,0008,487,00092,901,376
3Oct 14, 2026 00:533,89544,388,90126,981,0008,471,00092,897,280
4Oct 14, 2026 00:533,90044,492,09226,978,0008,515,00092,844,032
5Oct 14, 2026 00:533,90244,485,88126,931,0008,585,00092,897,280
6Oct 14, 2026 00:533,90444,640,91726,909,0008,622,00092,913,664
7Oct 14, 2026 00:533,90744,507,11926,965,0008,593,00092,831,744
8Oct 14, 2026 00:533,91344,632,01126,994,0008,617,00092,876,800
9Oct 14, 2026 00:533,92044,692,51827,174,0008,504,00092,889,088