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 listApr 22, 2025 18:05Aniruddha DebAniruddha DebScore: 99,785Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2025 18:0599,187928,214,574876,614,00025,988,000121,958,400
2Apr 22, 2025 18:0599,626931,079,246884,608,00021,990,000121,966,592
3Apr 22, 2025 18:0599,646931,440,018887,781,00018,995,000124,170,240
4Apr 22, 2025 18:0599,681931,608,883879,129,00027,972,000122,073,088
5Apr 22, 2025 18:0599,785932,863,328880,076,00027,970,000124,170,240
6Apr 22, 2025 18:0599,812934,560,128877,315,00030,975,000124,170,240
7Apr 22, 2025 18:05100,128930,586,398883,187,00027,974,000124,059,648
8Apr 22, 2025 18:05100,278932,843,876897,540,00014,992,000121,810,944
9Apr 22, 2025 18:05100,639941,328,537894,841,00020,972,000122,073,088