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 listMay 9, 2024 23:30Joad NacerJoad NacerScore: 3,984Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:303,77354,611,84323,224,00011,107,00092,954,624
2May 9, 2024 23:303,77559,731,97724,248,00010,103,00093,151,232
3May 9, 2024 23:303,80063,426,41025,429,0009,154,00092,880,896
4May 9, 2024 23:303,84865,595,32323,012,00012,006,00093,138,944
5May 9, 2024 23:303,98095,518,69336,215,619094,609,408
6May 9, 2024 23:303,983103,171,98636,246,088094,490,624
7May 9, 2024 23:303,98498,855,40436,256,836094,478,336
8May 9, 2024 23:304,27769,060,64123,954,00014,971,00093,155,328
9May 9, 2024 23:304,32365,247,36325,215,00014,120,00093,130,752
10May 9, 2024 23:306,92591,508,11927,007,00036,009,00093,286,400
11May 9, 2024 23:307,66899,014,88727,913,00041,869,00093,147,136
12May 9, 2024 23:307,82897,341,70027,090,00044,147,00093,310,976