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:35Joad NacerJoad NacerScore: 3,877Success
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:353,65061,769,27123,150,00010,065,00092,921,856
2May 9, 2024 23:353,65061,139,98922,144,00011,072,00092,889,088
3May 9, 2024 23:353,67854,405,22822,314,00011,157,00092,872,704
4May 9, 2024 23:353,70364,621,92121,806,00011,894,00092,950,528
5May 9, 2024 23:353,70460,027,33521,807,00011,895,00092,921,856
6May 9, 2024 23:353,85896,897,37535,104,371094,490,624
7May 9, 2024 23:353,877100,629,76635,276,301094,482,432
8May 9, 2024 23:353,894106,359,78735,439,767094,486,528
9May 9, 2024 23:355,42176,992,95624,160,00025,167,00093,167,616
10May 9, 2024 23:355,55881,350,48324,276,00026,299,00093,106,176
11May 9, 2024 23:356,84286,625,21325,107,00037,159,00093,138,944
12May 9, 2024 23:357,76098,533,46526,227,00044,385,00093,249,536