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:44Joad NacerJoad NacerScore: 3,975Success
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:443,77057,046,05523,206,00011,098,00092,897,280
2Apr 22, 2024 01:443,77865,794,56423,573,00010,804,00093,159,424
3Apr 22, 2024 01:443,78257,096,67625,309,0009,111,00092,966,912
4Apr 22, 2024 01:443,82460,517,89224,858,0009,943,00092,971,008
5Apr 22, 2024 01:443,84864,221,52324,009,00011,004,00092,876,800
6Apr 22, 2024 01:443,85363,597,99224,042,00011,019,00092,946,432
7Apr 22, 2024 01:443,975103,876,87936,174,990094,482,432
8Apr 22, 2024 01:443,992108,309,63236,330,886094,760,960
9Apr 22, 2024 01:443,996101,185,69936,363,975094,478,336
10Apr 22, 2024 01:444,61270,771,40823,980,00017,985,00092,909,568
11Apr 22, 2024 01:444,72868,738,80225,017,00018,012,00093,138,944
12Apr 22, 2024 01:445,68380,748,09225,856,00025,856,00093,089,792