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:11Joad NacerJoad NacerScore: 4,133Success
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:114,03465,762,23025,795,00010,913,00092,917,760
2Apr 22, 2024 00:114,05165,131,76126,902,0009,963,00092,893,184
3Apr 22, 2024 00:114,05568,913,49025,929,00010,970,00092,893,184
4Apr 22, 2024 00:114,07564,346,32927,062,00010,023,00092,848,128
5Apr 22, 2024 00:114,09662,754,69726,193,00011,081,00092,913,664
6Apr 22, 2024 00:114,10859,437,18326,272,00011,115,00092,921,856
7Apr 22, 2024 00:114,13365,068,28126,428,00011,181,00092,917,760
8Apr 22, 2024 00:114,29572,842,70527,059,00012,026,00092,999,680
9Apr 22, 2024 00:114,30598,799,45439,173,224094,486,528
10Apr 22, 2024 00:114,329111,843,92639,393,076094,486,528
11Apr 22, 2024 00:114,332105,971,61839,417,806094,486,528
12Apr 22, 2024 00:114,81473,693,74327,875,00015,928,00093,196,288