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 listMay 9, 2024 23:19Joad NacerJoad NacerScore: 4,107Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:193,87261,658,96224,163,00011,074,00092,844,032
2May 9, 2024 23:193,89757,818,82925,333,00010,133,00093,159,424
3May 9, 2024 23:193,93362,065,58023,859,00011,929,00092,909,568
4May 9, 2024 23:193,94062,440,35123,900,00011,950,00093,167,616
5May 9, 2024 23:193,96366,664,99725,047,00011,020,00092,897,280
6May 9, 2024 23:194,107110,118,78037,373,878094,490,624
7May 9, 2024 23:194,107101,021,29137,376,050094,482,432
8May 9, 2024 23:194,125104,913,45437,535,103094,482,432
9May 9, 2024 23:195,36478,994,36124,904,00023,908,00093,073,408
10May 9, 2024 23:196,33985,674,50927,848,00029,837,00093,184,000
11May 9, 2024 23:197,14192,997,14227,993,00036,991,00093,036,544
12May 9, 2024 23:197,956100,441,54429,162,00043,240,00093,290,496