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 listMay 9, 2024 23:56Joad NacerJoad NacerScore: 3,774Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:563,52862,586,48521,071,00011,037,00092,958,720
2May 9, 2024 23:563,54354,866,43222,168,00010,076,00092,901,376
3May 9, 2024 23:563,54752,813,15821,185,00011,097,00093,167,616
4May 9, 2024 23:563,60561,688,51820,877,00011,929,00092,905,472
5May 9, 2024 23:563,63059,665,26922,022,00011,011,00092,938,240
6May 9, 2024 23:563,765102,682,82034,265,097094,486,528
7May 9, 2024 23:563,774111,488,66734,339,310094,482,432
8May 9, 2024 23:563,803100,779,74734,604,490094,490,624
9May 9, 2024 23:564,27369,621,50621,936,00016,950,00093,159,424
10May 9, 2024 23:566,79389,870,20724,927,00036,892,00093,249,536
11May 9, 2024 23:567,28496,307,69627,118,00039,170,00093,327,360
12May 9, 2024 23:567,51694,102,23926,153,00042,247,00093,335,552