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 01:00Joad NacerJoad NacerScore: 4,254Success
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 01:004,03671,627,60526,804,0009,927,00092,913,664
2Apr 22, 2024 01:004,07365,481,67725,045,00012,021,00092,934,144
3Apr 22, 2024 01:004,07762,661,60525,066,00012,032,00092,876,800
4Apr 22, 2024 01:004,08266,542,47825,101,00012,048,00092,884,992
5Apr 22, 2024 01:004,08468,512,44825,112,00012,053,00092,962,816
6Apr 22, 2024 01:004,08563,207,55326,120,00011,050,00093,028,352
7Apr 22, 2024 01:004,254106,950,44938,709,245094,482,432
8Apr 22, 2024 01:004,25896,049,56538,745,542094,494,720
9Apr 22, 2024 01:004,267100,152,42738,827,573094,486,528
10Apr 22, 2024 01:004,45468,233,98026,346,00014,186,00092,979,200
11Apr 22, 2024 01:004,85475,657,37526,101,00018,070,00093,204,480
12Apr 22, 2024 01:005,48574,487,82427,951,00021,961,00093,184,000