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 01:42Joad NacerJoad NacerScore: 4,025Success
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 01:423,79263,612,75024,360,00010,150,00092,884,992
2Apr 22, 2024 01:423,79963,744,80325,422,0009,152,00092,930,048
3Apr 22, 2024 01:423,80260,626,89624,423,00010,176,00092,942,336
4Apr 22, 2024 01:423,82661,206,58425,864,0008,953,00092,917,760
5Apr 22, 2024 01:423,85761,023,49223,066,00012,034,00092,946,432
6Apr 22, 2024 01:423,88458,602,38023,224,00012,117,00092,897,280
7Apr 22, 2024 01:424,025118,623,38836,625,903094,752,768
8Apr 22, 2024 01:424,032106,192,79736,687,434094,482,432
9Apr 22, 2024 01:424,051110,532,94536,861,045094,494,720
10Apr 22, 2024 01:424,18966,158,33524,076,00014,044,00093,118,464
11Apr 22, 2024 01:424,58572,448,45025,829,00015,895,00093,208,576
12Apr 22, 2024 01:426,07183,199,33726,115,00029,128,00092,979,200