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, 2024 02:49Joad NacerJoad NacerScore: 4,147Success
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, 2024 02:494,04868,347,74024,889,00011,947,00092,925,952
2Apr 22, 2024 02:494,05266,429,96924,913,00011,958,00092,872,704
3Apr 22, 2024 02:494,05461,134,98826,919,0009,970,00093,028,352
4Apr 22, 2024 02:494,05565,004,14725,929,00010,970,00092,868,608
5Apr 22, 2024 02:494,06464,817,20624,986,00011,993,00092,934,144
6Apr 22, 2024 02:494,14591,699,23737,714,965094,482,432
7Apr 22, 2024 02:494,147105,849,72837,736,722094,605,312
8Apr 22, 2024 02:494,166108,351,77137,907,363094,486,528
9Apr 22, 2024 02:494,79169,890,65926,360,00017,235,00093,089,792
10Apr 22, 2024 02:495,68875,180,46926,875,00024,884,00093,118,464
11Apr 22, 2024 02:496,14688,403,94126,966,00028,963,00093,089,792
12Apr 22, 2024 02:498,01097,711,48929,956,00042,938,00093,089,792