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 31, 2024 06:41Mikhail ShirokovMikhail ShirokovScore: 18,843Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 31, 2024 06:4118,751195,661,035111,758,00058,872,000105,144,320
2Dec 31, 2024 06:4118,774198,349,394117,892,00052,951,000105,140,224
3Dec 31, 2024 06:4118,812193,577,610125,137,00046,050,000105,250,816
4Dec 31, 2024 06:4118,829195,385,879115,229,00056,111,000105,218,048
5Dec 31, 2024 06:4118,843193,852,304115,641,00055,826,000105,263,104
6Dec 31, 2024 06:4118,848200,639,620117,667,00053,847,000105,074,688
7Dec 31, 2024 06:4118,864200,107,349116,772,00054,893,000105,164,800
8Dec 31, 2024 06:4118,883199,126,027118,885,00052,949,000105,201,664
9Dec 31, 2024 06:4118,942202,572,860120,257,00052,111,000105,263,104