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 listJul 29, 2023 10:17Yurkov AlekseyYurkov AlekseyScore: 12,939Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 29, 2023 10:179,261145,192,11684,279,202092,561,408
2Jul 29, 2023 10:179,278143,954,48284,432,206092,557,312
3Jul 29, 2023 10:179,287154,154,98684,511,020092,569,600
4Jul 29, 2023 10:1712,918147,622,464100,622,00016,936,00092,471,296
5Jul 29, 2023 10:1712,929143,711,479100,702,00016,949,00092,704,768
6Jul 29, 2023 10:1712,929147,413,219100,704,00016,950,00092,700,672
7Jul 29, 2023 10:1712,939144,505,72299,784,00017,961,00092,446,720
8Jul 29, 2023 10:1712,951142,926,72397,879,00019,975,00092,704,768
9Jul 29, 2023 10:1712,968142,818,455102,007,00016,001,00092,704,768
10Jul 29, 2023 10:1713,035149,031,189100,675,00017,942,00092,106,752
11Jul 29, 2023 10:1713,090140,704,886102,100,00017,016,00092,205,056
12Jul 29, 2023 10:1713,289149,299,108100,941,00019,988,00092,184,576