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 listJan 11, 2025 10:39Mikhail ShirokovMikhail ShirokovScore: 10,262Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jan 11, 2025 10:3910,234114,073,26283,114,00010,013,000103,063,552
2Jan 11, 2025 10:3910,248113,904,76683,232,00010,028,000103,301,120
3Jan 11, 2025 10:3910,249115,701,28983,238,00010,028,000103,227,392
4Jan 11, 2025 10:3910,253112,077,26784,275,0009,029,000103,211,008
5Jan 11, 2025 10:3910,262114,334,49983,340,00010,040,000103,243,776
6Jan 11, 2025 10:3910,263122,014,43482,463,00010,928,000103,227,392
7Jan 11, 2025 10:3910,268119,487,31384,397,0009,042,000103,292,928
8Jan 11, 2025 10:3910,268119,925,41084,397,0009,042,000103,256,064
9Jan 11, 2025 10:3910,284122,393,73885,531,0008,050,000103,129,088