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 14:53Joad NacerJoad NacerScore: 3,363Success
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 14:533,17553,052,26518,928,0009,962,00093,081,600
2Jul 27, 2024 14:533,22559,468,45220,237,0009,106,00093,073,408
3Jul 27, 2024 14:533,23652,489,85120,309,0009,139,00092,864,512
4Jul 27, 2024 14:533,23647,944,59420,312,0009,140,00093,065,216
5Jul 27, 2024 14:533,25353,696,47120,413,0009,186,00093,081,600
6Jul 27, 2024 14:533,26856,684,05919,829,0009,914,00093,052,928
7Jul 27, 2024 14:533,36384,705,75430,601,513094,490,624
8Jul 27, 2024 14:533,36581,931,42230,621,522094,502,912
9Jul 27, 2024 14:533,37986,456,81830,752,295094,625,792
10Jul 27, 2024 14:534,64767,819,47521,142,00021,142,00092,958,720
11Jul 27, 2024 14:534,93173,932,12720,941,00023,933,00093,155,328
12Jul 27, 2024 14:535,81484,403,67721,961,00030,946,00093,184,000