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 listJul 27, 2024 19:59Joad NacerJoad NacerScore: 3,269Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 19:593,17159,887,76119,898,0008,954,00092,889,088
2Jul 27, 2024 19:593,23556,092,26120,301,0009,135,00093,073,408
3Jul 27, 2024 19:593,23855,874,10819,304,00010,160,00093,147,136
4Jul 27, 2024 19:593,24154,171,63420,340,0009,153,00093,057,024
5Jul 27, 2024 19:593,26453,699,96518,809,00010,889,00093,073,408
6Jul 27, 2024 19:593,26853,936,09919,827,0009,913,00093,077,504
7Jul 27, 2024 19:593,26956,923,22519,833,0009,916,00093,130,752
8Jul 27, 2024 19:593,37999,539,06530,748,381094,621,696
9Jul 27, 2024 19:593,38498,687,58630,791,610094,507,008
10Jul 27, 2024 19:593,39889,582,19230,923,454094,502,912
11Jul 27, 2024 19:594,64668,917,22620,131,00022,145,00093,081,600
12Jul 27, 2024 19:596,59680,849,31923,008,00037,014,00093,102,080