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 22:56Joad NacerJoad NacerScore: 3,951Success
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 22:563,72159,867,55922,908,00010,956,00092,897,280
2May 9, 2024 22:563,73458,221,62722,984,00010,992,00092,909,568
3May 9, 2024 22:563,73661,617,24123,996,0009,998,00092,938,240
4May 9, 2024 22:563,73861,235,01525,015,0009,005,00092,901,376
5May 9, 2024 22:563,81762,969,08322,827,00011,909,00093,011,968
6May 9, 2024 22:563,82659,456,15723,873,00010,942,00093,081,600
7May 9, 2024 22:563,95197,597,25335,957,056094,482,432
8May 9, 2024 22:563,97394,183,66836,158,543094,486,528
9May 9, 2024 22:563,98787,797,84636,279,942094,490,624
10May 9, 2024 22:565,88778,312,07226,280,00027,291,00093,032,448
11May 9, 2024 22:567,13993,401,76026,985,00037,980,00093,220,864
12May 9, 2024 22:567,38293,931,01327,070,00040,105,00093,302,784