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:23Joad NacerJoad NacerScore: 3,472Success
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:233,27255,781,70420,844,0008,933,00093,073,408
2Jul 27, 2024 14:233,36359,715,21221,424,0009,182,00093,024,256
3Jul 27, 2024 14:233,36958,479,08521,460,0009,197,00093,196,288
4Jul 27, 2024 14:233,38752,689,48319,885,00010,936,00093,028,352
5Jul 27, 2024 14:233,38952,172,14720,889,0009,947,00092,893,184
6Jul 27, 2024 14:233,44954,325,65021,264,00010,125,00093,138,944
7Jul 27, 2024 14:233,47289,723,16331,596,848094,502,912
8Jul 27, 2024 14:233,49891,454,19431,829,656094,502,912
9Jul 27, 2024 14:233,50096,050,84331,849,749094,629,888
10Jul 27, 2024 14:235,18170,233,15023,071,00024,074,00093,040,640
11Jul 27, 2024 14:236,50180,946,00723,062,00036,098,00093,114,368
12Jul 27, 2024 14:237,05688,612,14325,082,00039,128,00093,081,600