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 21, 2024 23:08Joad NacerJoad NacerScore: 4,727Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:084,69768,872,32630,813,00011,927,00092,876,800
2Apr 21, 2024 23:084,70171,557,12530,842,00011,939,00092,876,800
3Apr 21, 2024 23:084,70269,480,39731,845,00010,946,00092,884,992
4Apr 21, 2024 23:084,70669,299,24430,877,00011,952,00092,884,992
5Apr 21, 2024 23:084,70769,762,34830,880,00011,953,00092,987,392
6Apr 21, 2024 23:084,72174,228,40130,970,00011,988,00092,884,992
7Apr 21, 2024 23:084,72770,273,02831,012,00012,005,00092,925,952
8Apr 21, 2024 23:084,865107,543,29644,275,022094,486,528
9Apr 21, 2024 23:084,884105,815,82644,443,429094,490,624
10Apr 21, 2024 23:084,888107,548,70644,484,629094,482,432
11Apr 21, 2024 23:085,46577,857,83132,822,00016,908,00093,126,656
12Apr 21, 2024 23:085,56380,623,59232,397,00018,223,00093,167,616