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 listMay 21, 2024 21:46Joad NacerJoad NacerScore: 3,775Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 21, 2024 21:463,54555,399,60621,172,00011,090,00092,917,760
2May 21, 2024 21:463,62261,674,86320,977,00011,986,00092,884,992
3May 21, 2024 21:463,62558,670,60420,995,00011,997,00092,917,760
4May 21, 2024 21:463,63860,781,34921,065,00012,037,00092,868,608
5May 21, 2024 21:463,66362,958,60121,570,00011,765,00092,905,472
6May 21, 2024 21:463,77298,550,07734,329,150094,490,624
7May 21, 2024 21:463,77588,486,06734,351,339094,486,528
8May 21, 2024 21:463,796107,849,67034,547,432094,490,624
9May 21, 2024 21:465,93379,435,62124,994,00028,993,00093,106,176
10May 21, 2024 21:466,21784,265,60924,247,00032,329,00093,044,736
11May 21, 2024 21:466,61492,432,57825,079,00035,111,00093,298,688
12May 21, 2024 21:466,92995,156,93925,022,00038,033,00093,077,504