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 listJul 10, 2024 16:43Joad NacerJoad NacerScore: 4,580Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 10, 2024 16:434,400127,838,90540,044,292094,494,720
2Jul 10, 2024 16:434,405113,958,75540,088,541094,490,624
3Jul 10, 2024 16:434,424107,201,46140,255,220094,486,528
4Jul 10, 2024 16:434,49571,234,01029,930,00010,974,00093,147,136
5Jul 10, 2024 16:434,53563,849,92531,206,00010,066,00092,958,720
6Jul 10, 2024 16:434,54263,416,66329,238,00012,098,00092,901,376
7Jul 10, 2024 16:434,58067,723,01531,752,0009,922,00092,958,720
8Jul 10, 2024 16:434,58768,812,67029,817,00011,926,00093,155,328
9Jul 10, 2024 16:434,76066,241,11031,230,00012,089,00093,097,984
10Jul 10, 2024 16:438,171101,011,20234,163,00040,192,00093,241,344
11Jul 10, 2024 16:438,387106,187,97634,143,00042,176,00093,310,976
12Jul 10, 2024 16:438,425109,485,32834,298,00042,369,00093,388,800