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:33Joad NacerJoad NacerScore: 3,942Success
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:333,76758,730,56124,201,00010,083,00092,905,472
2Apr 22, 2024 01:333,80166,569,75624,414,00010,172,00092,909,568
3Apr 22, 2024 01:333,81962,048,20624,826,0009,930,00092,934,144
4Apr 22, 2024 01:333,82562,336,43322,875,00011,934,00092,889,088
5Apr 22, 2024 01:333,84559,699,42422,994,00011,997,00093,134,848
6Apr 22, 2024 01:333,84667,096,66324,000,00011,000,00092,938,240
7Apr 22, 2024 01:333,94297,437,78035,872,688094,752,768
8Apr 22, 2024 01:333,975103,450,53836,172,879094,478,336
9Apr 22, 2024 01:334,00898,476,37736,474,738094,617,600
10Apr 22, 2024 01:334,11059,899,29824,259,00013,140,00093,011,968
11Apr 22, 2024 01:334,13963,505,37924,780,00012,886,00093,040,640
12Apr 22, 2024 01:334,23666,683,24224,346,00014,202,00093,118,464