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 10, 2024 00:00Joad NacerJoad NacerScore: 3,966Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 10, 2024 00:003,77862,742,03923,257,00011,123,00092,897,280
2May 10, 2024 00:003,79166,477,12024,354,00010,147,00092,897,280
3May 10, 2024 00:003,82160,627,83323,845,00010,929,00092,966,912
4May 10, 2024 00:003,82561,689,28622,872,00011,933,00092,901,376
5May 10, 2024 00:003,84865,763,43725,015,00010,006,00092,934,144
6May 10, 2024 00:003,85956,733,62323,078,00012,040,00092,921,856
7May 10, 2024 00:003,96693,107,54436,091,600094,494,720
8May 10, 2024 00:003,97497,081,91036,162,586094,490,624
9May 10, 2024 00:003,98195,986,19536,228,312094,486,528
10May 10, 2024 00:005,31378,777,23526,190,00022,161,00093,114,368
11May 10, 2024 00:006,73387,406,17126,115,00035,155,00093,323,264
12May 10, 2024 00:007,31995,733,37527,247,00039,358,00093,097,984