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 00:00Joad NacerJoad NacerScore: 3,962Success
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 00:003,87462,748,65424,174,00011,080,00092,942,336
2Apr 22, 2024 00:003,91463,907,49726,456,0009,158,00092,835,840
3Apr 22, 2024 00:003,91461,798,54325,444,00010,177,00092,876,800
4Apr 22, 2024 00:003,94160,402,80423,906,00011,953,00092,954,624
5Apr 22, 2024 00:003,94661,945,23123,941,00011,970,00092,901,376
6Apr 22, 2024 00:003,95464,139,23523,985,00011,992,00092,938,240
7Apr 22, 2024 00:003,96261,867,90225,039,00011,017,00092,860,416
8Apr 22, 2024 00:003,98658,543,18924,185,00012,092,00092,938,240
9Apr 22, 2024 00:004,377109,335,12539,834,574094,490,624
10Apr 22, 2024 00:004,401111,530,39040,050,712094,486,528
11Apr 22, 2024 00:004,423102,330,30940,248,289094,613,504
12Apr 22, 2024 00:006,40980,732,46827,149,00031,171,00093,081,600