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 21, 2024 23:55Joad NacerJoad NacerScore: 4,032Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:553,94361,689,35925,917,0009,968,00092,917,760
2Apr 21, 2024 23:553,96563,058,62325,056,00011,024,00092,876,800
3Apr 21, 2024 23:554,00161,180,30425,283,00011,124,00092,893,184
4Apr 21, 2024 23:554,00460,093,88825,305,00011,134,00092,934,144
5Apr 21, 2024 23:554,01762,737,18426,398,00010,153,00092,921,856
6Apr 21, 2024 23:554,03162,176,72724,787,00011,897,00092,909,568
7Apr 21, 2024 23:554,03261,709,87924,790,00011,899,00092,962,816
8Apr 21, 2024 23:554,168103,924,65437,924,414094,748,672
9Apr 21, 2024 23:554,168117,010,16437,927,446094,490,624
10Apr 21, 2024 23:554,201102,887,38238,226,960094,621,696
11Apr 21, 2024 23:556,59984,755,36628,024,00032,027,00093,130,752
12Apr 21, 2024 23:557,61897,615,23429,134,00040,186,00093,310,976