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:28Joad NacerJoad NacerScore: 4,021Success
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:283,76457,566,32223,173,00011,082,00092,901,376
2Apr 22, 2024 01:283,77856,923,14724,266,00010,111,00092,999,680
3Apr 22, 2024 01:283,81566,034,82923,807,00010,911,00092,958,720
4Apr 22, 2024 01:283,82465,404,12822,866,00011,930,00092,889,088
5Apr 22, 2024 01:283,83564,857,82922,931,00011,964,00092,872,704
6Apr 22, 2024 01:283,84863,148,88625,013,00010,005,00093,122,560
7Apr 22, 2024 01:284,02191,931,00336,593,702094,613,504
8Apr 22, 2024 01:284,04789,405,45336,828,173094,498,816
9Apr 22, 2024 01:284,059102,994,52836,934,660094,482,432
10Apr 22, 2024 01:285,22477,259,53525,286,00022,251,00093,171,712
11Apr 22, 2024 01:285,30973,450,20825,163,00023,150,00093,159,424
12Apr 22, 2024 01:286,05380,873,67425,039,00030,046,00093,110,272