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:16Joad NacerJoad NacerScore: 4,138Success
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:163,76557,623,20822,168,00012,091,00092,913,664
2Apr 22, 2024 01:163,78360,831,21923,285,00011,136,00092,893,184
3Apr 22, 2024 01:163,79558,632,98223,361,00011,172,00092,921,856
4Apr 22, 2024 01:163,80164,372,03823,397,00011,190,00093,192,192
5Apr 22, 2024 01:163,81659,356,83022,822,00011,907,00092,876,800
6Apr 22, 2024 01:163,81767,951,43122,828,00011,910,00092,925,952
7Apr 22, 2024 01:164,13899,245,48637,656,626094,490,624
8Apr 22, 2024 01:164,143101,757,01737,699,400094,486,528
9Apr 22, 2024 01:164,166104,118,27037,911,707094,482,432
10Apr 22, 2024 01:164,70871,333,59424,911,00017,936,00093,184,000
11Apr 22, 2024 01:165,25574,603,13223,911,00023,911,00093,171,712
12Apr 22, 2024 01:165,25779,380,45123,920,00023,920,00093,167,616