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 listDec 30, 2024 15:55Mikhail ShirokovMikhail ShirokovScore: 45,805Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 30, 2024 15:5545,654444,689,278328,569,00086,886,000111,493,120
2Dec 30, 2024 15:5545,664442,789,942327,639,00087,903,000111,439,872
3Dec 30, 2024 15:5545,704446,415,598324,929,00090,980,000111,390,720
4Dec 30, 2024 15:5545,714442,135,875319,001,00097,000,000111,427,584
5Dec 30, 2024 15:5545,805444,389,004326,865,00089,962,000111,575,040
6Dec 30, 2024 15:5545,884441,972,320328,640,00088,902,000111,575,040
7Dec 30, 2024 15:5545,956449,636,483331,160,00087,042,000111,345,664
8Dec 30, 2024 15:5546,151451,863,883321,980,00097,994,000111,419,392
9Dec 30, 2024 15:5548,297468,183,996344,610,00094,892,000111,538,176