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:48Joad NacerJoad NacerScore: 4,420Success
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:484,26364,919,19127,854,00010,942,00092,909,568
2Apr 22, 2024 01:484,26963,671,04127,889,00010,956,00092,925,952
3Apr 22, 2024 01:484,28064,983,71027,962,00010,985,00092,872,704
4Apr 22, 2024 01:484,28668,051,98829,003,00010,001,00092,942,336
5Apr 22, 2024 01:484,31962,408,98527,211,00012,094,00092,938,240
6Apr 22, 2024 01:484,32464,274,22028,253,00011,099,00092,987,392
7Apr 22, 2024 01:484,420106,140,27240,222,595094,478,336
8Apr 22, 2024 01:484,437113,592,74440,372,386094,490,624
9Apr 22, 2024 01:484,467121,872,14240,651,231094,482,432
10Apr 22, 2024 01:484,54370,464,29828,234,00013,108,00093,110,272
11Apr 22, 2024 01:484,85473,350,96829,115,00015,059,00093,147,136
12Apr 22, 2024 01:485,45272,296,07329,767,00019,845,00093,073,408