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 06:27Karthik ReddyKarthik ReddyScore: 3,799Success
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 06:333,75943,069,40125,877,0008,332,00092,725,248
2Oct 14, 2026 06:333,77843,416,77826,017,0008,369,00092,774,400
3Oct 14, 2026 06:333,78443,410,24026,035,0008,408,00092,786,688
4Oct 14, 2026 06:333,78443,336,58526,101,0008,334,00092,708,864
5Oct 14, 2026 06:333,79943,554,05626,227,0008,348,00092,696,576
6Oct 14, 2026 06:333,80043,560,55126,253,0008,335,00092,741,632
7Oct 14, 2026 06:333,82643,823,70426,376,0008,444,00092,704,768
8Oct 14, 2026 06:333,84743,992,84426,603,0008,411,00092,749,824
9Oct 14, 2026 06:333,85944,129,14626,684,0008,441,00092,712,960