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:41Joad NacerJoad NacerScore: 3,414Success
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:413,21455,825,88519,160,00010,084,00092,950,528
2Jul 27, 2024 14:413,22052,164,48920,207,0009,093,00093,040,640
3Jul 27, 2024 14:413,29954,246,66719,015,00011,009,00093,057,024
4Jul 27, 2024 14:413,30058,077,12419,021,00011,012,00092,958,720
5Jul 27, 2024 14:413,30550,599,85420,049,00010,024,00093,122,560
6Jul 27, 2024 14:413,31352,047,39219,093,00011,054,00092,934,144
7Jul 27, 2024 14:413,41489,231,05831,068,753094,498,816
8Jul 27, 2024 14:413,43187,602,87231,220,216094,502,912
9Jul 27, 2024 14:413,45299,332,43631,416,004094,498,816
10Jul 27, 2024 14:415,35677,654,48522,879,00025,864,00093,184,000
11Jul 27, 2024 14:415,59878,579,45021,977,00028,969,00093,093,888
12Jul 27, 2024 14:415,74475,232,33622,115,00030,157,00093,196,288