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 28, 2024 17:57Mikhail ShirokovMikhail ShirokovScore: 1,059,770Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 28, 2024 17:571,055,8139,645,414,2709,057,422,000550,478,00094,564,352
2Dec 28, 2024 17:571,057,4969,661,188,5169,121,670,000501,541,00094,568,448
3Dec 28, 2024 17:571,057,8879,659,786,8339,104,223,000522,553,00094,621,696
4Dec 28, 2024 17:571,059,7639,690,779,2139,118,346,000525,501,00094,621,696
5Dec 28, 2024 17:571,059,7709,683,643,6699,123,451,000520,455,00094,613,504
6Dec 28, 2024 17:571,067,6339,754,139,7289,206,014,000509,447,00094,642,176
7Dec 28, 2024 17:571,071,1239,782,676,7799,190,610,000556,613,00094,621,696
8Dec 28, 2024 17:571,074,4949,810,079,7539,224,300,000553,597,00094,760,960
9Dec 28, 2024 17:571,084,7839,907,977,4789,242,127,000629,395,00094,650,368