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,352Success
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:424,26264,924,82327,847,00010,940,00092,934,144
2Apr 22, 2024 01:424,31867,694,21428,214,00011,084,00092,884,992
3Apr 22, 2024 01:424,32169,885,16229,240,00010,083,00092,946,432
4Apr 22, 2024 01:424,32361,905,64027,232,00012,103,00092,905,472
5Apr 22, 2024 01:424,33270,450,49029,314,00010,108,00092,917,760
6Apr 22, 2024 01:424,34665,405,66428,395,00011,155,00093,184,000
7Apr 22, 2024 01:424,35267,971,00428,430,00011,169,00092,942,336
8Apr 22, 2024 01:424,47766,792,23427,824,00012,918,00093,175,808
9Apr 22, 2024 01:424,501118,585,04540,957,102094,490,624
10Apr 22, 2024 01:424,502107,798,85840,972,287094,478,336
11Apr 22, 2024 01:424,508116,661,81741,026,073094,490,624
12Apr 22, 2024 01:425,42874,535,49229,236,00020,163,00093,093,888