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:46Mikhail ShirokovMikhail ShirokovScore: 18,740Success
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:4618,607193,001,057114,217,00055,104,000105,111,552
2Dec 31, 2024 06:4618,638196,084,489114,732,00054,871,000105,168,896
3Dec 31, 2024 06:4618,640195,483,957115,744,00053,881,000105,111,552
4Dec 31, 2024 06:4618,672198,104,455115,942,00053,973,000105,164,800
5Dec 31, 2024 06:4618,740203,650,212118,678,00051,859,000105,127,936
6Dec 31, 2024 06:4618,745196,526,643109,373,00061,209,000105,275,392
7Dec 31, 2024 06:4618,748197,748,983114,734,00055,870,000105,111,552
8Dec 31, 2024 06:4618,753194,107,841118,760,00051,895,000105,115,648
9Dec 31, 2024 06:4618,756193,154,289119,778,00050,905,000105,193,472