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 20:02Joad NacerJoad NacerScore: 3,386Success
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 20:023,30848,627,85120,067,00010,033,00093,126,656
2Jul 27, 2024 20:023,31253,622,52120,090,00010,045,00092,925,952
3Jul 27, 2024 20:023,31352,978,61819,095,00011,055,00092,913,664
4Jul 27, 2024 20:023,32353,805,30520,162,00010,081,00093,069,312
5Jul 27, 2024 20:023,32953,088,08121,209,0009,089,00093,085,696
6Jul 27, 2024 20:023,34461,653,57921,299,0009,128,00093,073,408
7Jul 27, 2024 20:023,38689,648,83730,813,523094,765,056
8Jul 27, 2024 20:023,393118,333,32330,873,432094,494,720
9Jul 27, 2024 20:023,40989,669,80431,022,494094,507,008
10Jul 27, 2024 20:024,23169,266,87921,278,00017,225,00093,106,176
11Jul 27, 2024 20:025,04576,630,50720,959,00024,951,00093,245,440
12Jul 27, 2024 20:026,92191,180,20323,992,00038,987,00093,286,400