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:12Joad NacerJoad NacerScore: 4,023Success
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:123,81665,341,83823,814,00010,915,00093,196,288
2Apr 22, 2024 01:123,81759,705,92923,820,00010,917,00092,921,856
3Apr 22, 2024 01:123,81960,754,18823,833,00010,923,00092,946,432
4Apr 22, 2024 01:123,84459,209,23322,988,00011,994,00092,925,952
5Apr 22, 2024 01:123,86559,212,56823,110,00012,057,00092,860,416
6Apr 22, 2024 01:123,87557,999,06824,178,00011,081,00092,921,856
7Apr 22, 2024 01:124,023108,164,41336,609,088094,494,720
8Apr 22, 2024 01:124,044110,775,24336,802,987094,609,408
9Apr 22, 2024 01:124,061103,448,70436,951,651094,490,624
10Apr 22, 2024 01:124,16466,213,31723,930,00013,959,00092,954,624
11Apr 22, 2024 01:124,73969,263,34925,071,00018,051,00093,147,136
12Apr 22, 2024 01:125,04969,748,06724,972,00020,976,00093,134,848