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 21, 2024 23:07Joad NacerJoad NacerScore: 5,530Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:075,15879,751,46431,959,00014,981,00092,942,336
2Apr 21, 2024 23:075,21473,838,69633,312,00014,132,00092,893,184
3Apr 21, 2024 23:075,22976,378,53832,712,00014,869,00092,880,896
4Apr 21, 2024 23:075,25577,136,78531,881,00015,940,00092,913,664
5Apr 21, 2024 23:075,27179,641,38531,976,00015,988,00093,155,328
6Apr 21, 2024 23:075,28579,363,89333,065,00015,029,00092,909,568
7Apr 21, 2024 23:075,530122,964,26550,321,299094,654,464
8Apr 21, 2024 23:075,534107,544,98950,363,296094,666,752
9Apr 21, 2024 23:075,557116,617,53550,567,261094,658,560
10Apr 21, 2024 23:076,62587,314,07532,152,00028,133,00092,872,704
11Apr 21, 2024 23:079,246112,342,76834,056,00050,083,00093,265,920
12Apr 21, 2024 23:079,321113,552,34935,341,00049,477,00093,257,728