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 11:06Karthik ReddyKarthik ReddyScore: 3,686Success
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 11:123,64542,162,84024,759,0008,416,00092,884,992
2Oct 14, 2026 11:123,67242,465,02124,981,0008,442,00092,852,224
3Oct 14, 2026 11:123,67642,550,89625,060,0008,400,00092,872,704
4Oct 14, 2026 11:123,68042,459,95324,923,0008,567,00092,868,608
5Oct 14, 2026 11:123,68642,804,14325,102,0008,443,00092,856,320
6Oct 14, 2026 11:123,70142,706,02625,132,0008,551,00092,884,992
7Oct 14, 2026 11:123,70842,663,06525,124,0008,627,00092,925,952
8Oct 14, 2026 11:123,73542,929,18125,456,0008,538,00092,831,744
9Oct 14, 2026 11:123,79443,479,16425,983,0008,551,00092,844,032