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,492Success
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,23552,034,19120,301,0009,135,00092,934,144
2Jul 27, 2024 14:413,33049,362,59321,215,0009,092,00093,126,656
3Jul 27, 2024 14:413,34255,064,82321,290,0009,124,00093,179,904
4Jul 27, 2024 14:413,34961,572,23821,335,0009,143,00092,876,800
5Jul 27, 2024 14:413,35453,491,07121,366,0009,157,00093,024,256
6Jul 27, 2024 14:413,484109,523,33931,708,043094,507,008
7Jul 27, 2024 14:413,49288,148,93831,781,727094,502,912
8Jul 27, 2024 14:413,49794,566,10431,821,849094,638,080
9Jul 27, 2024 14:413,70555,266,44120,825,00012,892,00093,184,000
10Jul 27, 2024 14:415,65177,397,56023,193,00028,235,00093,196,288
11Jul 27, 2024 14:415,72976,057,76023,059,00029,074,00093,061,120
12Jul 27, 2024 14:416,47581,546,00623,970,00034,957,00093,310,976