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:39Joad NacerJoad NacerScore: 3,625Success
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:393,33156,563,23521,218,0009,093,00093,143,040
2Jul 27, 2024 14:393,40858,197,89221,011,00010,005,00093,163,520
3Jul 27, 2024 14:393,41254,688,28420,031,00011,017,00093,048,832
4Jul 27, 2024 14:393,42554,449,19521,113,00010,054,00093,138,944
5Jul 27, 2024 14:393,42757,153,37321,124,00010,059,00092,921,856
6Jul 27, 2024 14:393,43852,847,26922,202,0009,082,00093,126,656
7Jul 27, 2024 14:393,625102,387,65832,985,696094,502,912
8Jul 27, 2024 14:393,63598,084,34933,075,759094,638,080
9Jul 27, 2024 14:393,653104,778,05433,243,634094,633,984
10Jul 27, 2024 14:394,76877,508,70322,199,00021,190,00092,999,680
11Jul 27, 2024 14:396,71190,755,72323,028,00038,046,00093,249,536
12Jul 27, 2024 14:396,76085,471,93323,193,00038,320,00093,069,312