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 07:11Karthik ReddyKarthik ReddyScore: 3,577Success
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 07:163,55041,271,27723,882,0008,427,00092,880,896
2Oct 14, 2026 07:163,55441,970,72623,882,0008,464,00092,909,568
3Oct 14, 2026 07:163,57141,405,02623,875,0008,630,00092,880,896
4Oct 14, 2026 07:163,57441,452,60623,997,0008,529,00092,868,608
5Oct 14, 2026 07:163,57741,500,46724,103,0008,452,00092,889,088
6Oct 14, 2026 07:163,57941,777,66724,079,0008,497,00092,893,184
7Oct 14, 2026 07:163,60141,739,82824,364,0008,407,00092,864,512
8Oct 14, 2026 07:163,63942,063,64724,676,0008,444,00092,844,032
9Oct 14, 2026 07:163,64042,128,26724,489,0008,641,00092,860,416