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 listNov 29, 2024 18:12E SequeiraE SequeiraScore: 930,947Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Nov 29, 2024 18:12919,6528,401,098,5128,321,888,00046,942,00094,568,448
2Nov 29, 2024 18:12921,3828,416,352,4398,350,608,00033,965,00094,556,160
3Nov 29, 2024 18:12925,6288,455,302,9568,385,243,00037,969,00094,609,408
4Nov 29, 2024 18:12927,4178,487,930,6348,406,533,00032,966,00094,810,112
5Nov 29, 2024 18:12930,9478,508,929,0808,437,652,00033,966,00094,810,112
6Nov 29, 2024 18:12931,6848,509,600,8058,434,350,00043,970,00094,760,960
7Nov 29, 2024 18:12931,7548,518,373,3338,440,998,00037,959,00094,556,160
8Nov 29, 2024 18:12934,3198,540,502,1248,465,333,00036,966,00094,601,216
9Nov 29, 2024 18:12936,9548,562,968,3078,479,309,00046,974,00094,601,216