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 15:05Joad NacerJoad NacerScore: 3,367Success
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 15:053,14356,016,23519,406,0009,192,00093,073,408
2Jul 27, 2024 15:053,17059,098,78820,890,0007,958,00092,880,896
3Jul 27, 2024 15:053,19152,062,24119,023,00010,012,00093,130,752
4Jul 27, 2024 15:053,23155,709,09120,275,0009,124,00093,044,736
5Jul 27, 2024 15:053,23854,667,62320,320,0009,144,00092,991,488
6Jul 27, 2024 15:053,26859,390,14419,827,0009,913,00092,921,856
7Jul 27, 2024 15:053,36786,380,72330,637,169094,638,080
8Jul 27, 2024 15:053,37291,141,08230,683,171094,498,816
9Jul 27, 2024 15:053,38498,595,28730,792,721094,498,816
10Jul 27, 2024 15:056,65296,831,83922,195,00038,337,00093,138,944
11Jul 27, 2024 15:057,05688,718,27123,074,00041,132,00093,184,000
12Jul 27, 2024 15:057,277101,588,15524,081,00042,142,00093,204,480