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:01Joad NacerJoad NacerScore: 4,433Success
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:014,34867,015,75329,425,00010,146,00092,938,240
2Apr 22, 2024 00:014,39072,426,30527,966,00011,985,00092,897,280
3Apr 22, 2024 00:014,39766,679,68829,009,00011,003,00093,126,656
4Apr 22, 2024 00:014,40069,546,99828,030,00012,012,00092,897,280
5Apr 22, 2024 00:014,40365,836,87128,047,00012,020,00092,893,184
6Apr 22, 2024 00:014,42467,707,06428,184,00012,078,00092,942,336
7Apr 22, 2024 00:014,43362,624,87329,248,00011,094,00092,930,048
8Apr 22, 2024 00:014,839101,846,07644,031,984094,486,528
9Apr 22, 2024 00:014,850106,576,61744,139,376094,498,816
10Apr 22, 2024 00:014,870106,153,87244,312,524094,490,624
11Apr 22, 2024 00:015,68982,203,15728,873,00022,899,00093,196,288
12Apr 22, 2024 00:016,33583,391,56330,814,00026,838,00093,114,368