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 listJul 27, 2024 14:36Joad NacerJoad NacerScore: 3,511Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 14:363,35860,337,25421,391,0009,167,00093,126,656
2Jul 27, 2024 14:363,36654,819,69419,763,00010,870,00093,032,448
3Jul 27, 2024 14:363,38454,466,10920,862,0009,934,00092,884,992
4Jul 27, 2024 14:363,38556,530,04220,870,0009,938,00093,077,504
5Jul 27, 2024 14:363,475113,770,22931,623,760094,502,912
6Jul 27, 2024 14:363,503105,728,00831,873,124094,502,912
7Jul 27, 2024 14:363,51160,500,85119,970,00011,982,00093,122,560
8Jul 27, 2024 14:363,522106,103,12232,046,605094,490,624
9Jul 27, 2024 14:364,54571,506,57220,174,00021,183,00092,966,912
10Jul 27, 2024 14:364,67167,589,03022,263,00020,239,00092,979,200
11Jul 27, 2024 14:367,15889,135,96525,053,00040,085,00093,114,368
12Jul 27, 2024 14:367,37495,694,76224,037,00043,068,00093,110,272