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 00:05Joad NacerJoad NacerScore: 4,035Success
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 00:053,94766,909,79324,946,00010,976,00092,942,336
2Apr 22, 2024 00:053,94865,083,49024,952,00010,979,00092,901,376
3Apr 22, 2024 00:053,95563,711,71825,996,0009,998,00092,962,816
4Apr 22, 2024 00:053,97762,681,43725,135,00011,059,00092,934,144
5Apr 22, 2024 00:053,99858,480,71625,267,00011,117,00092,966,912
6Apr 22, 2024 00:054,01366,671,94725,360,00011,158,00092,860,416
7Apr 22, 2024 00:054,03568,027,09624,811,00011,909,00092,917,760
8Apr 22, 2024 00:054,04565,845,49925,866,00010,943,00092,925,952
9Apr 22, 2024 00:054,171111,398,99837,953,665094,490,624
10Apr 22, 2024 00:054,176117,425,79838,004,253094,748,672
11Apr 22, 2024 00:054,186102,882,88038,097,071094,601,216
12Apr 22, 2024 00:054,55866,630,94326,303,00015,175,00093,196,288