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 21, 2024 23:34Joad NacerJoad NacerScore: 3,937Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:343,87658,543,89724,189,00011,086,00093,138,944
2Apr 21, 2024 23:343,88957,639,85326,288,0009,099,00092,909,568
3Apr 21, 2024 23:343,89663,222,86622,285,00013,168,00092,860,416
4Apr 21, 2024 23:343,90264,825,54623,335,00012,174,00092,938,240
5Apr 21, 2024 23:343,90868,310,90726,421,0009,145,00092,954,624
6Apr 21, 2024 23:343,93561,634,02026,853,0008,951,00092,966,912
7Apr 21, 2024 23:343,93762,510,81723,887,00011,943,00093,175,808
8Apr 21, 2024 23:344,33399,510,42039,430,728094,494,720
9Apr 21, 2024 23:344,354102,493,42739,619,744094,494,720
10Apr 21, 2024 23:344,366103,075,90739,732,602094,605,312
11Apr 21, 2024 23:345,78882,217,14427,827,00024,846,00093,073,408
12Apr 21, 2024 23:346,07780,924,41432,174,00023,125,00093,085,696