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 30, 2025 22:52Aniruddha DebAniruddha DebScore: 100,811Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 30, 2025 22:51100,651941,359,681899,940,00015,981,000121,810,944
2Apr 30, 2025 22:51100,702944,225,166892,405,00023,984,000122,073,088
3Apr 30, 2025 22:52100,704940,135,260889,425,00026,982,000124,059,648
4Apr 30, 2025 22:52100,772947,910,338894,051,00022,975,000121,966,592
5Apr 30, 2025 22:52100,811939,836,215893,398,00023,983,000121,962,496
6Apr 30, 2025 22:51100,822944,085,756893,494,00023,986,000121,962,496
7Apr 30, 2025 22:52100,825941,205,436895,522,00021,988,000124,170,240
8Apr 30, 2025 22:52100,924949,584,241895,426,00022,985,000124,145,664
9Apr 30, 2025 22:52101,003942,632,990894,148,00024,976,000121,966,592