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 22, 2024 00:42Joad NacerJoad NacerScore: 3,725Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 00:423,42660,782,57720,113,00011,062,00092,913,664
2May 22, 2024 00:423,45554,431,99020,287,00011,158,00093,159,424
3May 22, 2024 00:423,46757,481,67820,703,00010,844,00092,913,664
4May 22, 2024 00:423,51156,177,69019,970,00011,982,00092,868,608
5May 22, 2024 00:423,69196,167,13633,584,899094,605,312
6May 22, 2024 00:423,69389,130,61433,609,078094,482,432
7May 22, 2024 00:423,725101,954,76933,896,352094,482,432
8May 22, 2024 00:424,02463,607,03321,363,00015,259,00093,011,968
9May 22, 2024 00:425,13374,053,78321,865,00024,847,00093,097,984
10May 22, 2024 00:426,13679,720,28323,932,00031,910,00093,073,408
11May 22, 2024 00:427,56196,932,58624,928,00043,874,00093,184,000
12May 22, 2024 00:427,59892,853,15226,053,00043,088,00093,171,712