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 9, 2024 23:38Joad NacerJoad NacerScore: 4,106Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:383,54362,174,31921,156,00011,082,00092,958,720
2May 9, 2024 23:383,59563,377,86621,808,00010,904,00092,938,240
3May 9, 2024 23:383,60058,198,50520,848,00011,913,00092,872,704
4May 9, 2024 23:383,75395,138,71134,153,473094,486,528
5May 9, 2024 23:383,77893,275,52334,384,062094,494,720
6May 9, 2024 23:383,79089,818,44934,488,008094,486,528
7May 9, 2024 23:384,10665,397,74222,215,00015,146,00093,110,272
8May 9, 2024 23:384,73769,820,84923,059,00020,051,00093,102,080
9May 9, 2024 23:384,81869,165,65822,918,00020,926,00093,085,696
10May 9, 2024 23:387,62993,463,31626,159,00043,264,00093,257,728
11May 9, 2024 23:387,63995,164,09626,193,00043,319,00093,278,208
12May 9, 2024 23:387,71696,187,46126,080,00044,136,00093,192,192