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 listJun 24, 2024 20:22Joad NacerJoad NacerScore: 3,657Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 24, 2024 20:223,38758,058,05317,899,00012,927,00092,901,376
2Jun 24, 2024 20:223,40352,783,21418,978,00011,986,00092,913,664
3Jun 24, 2024 20:223,40364,214,31320,979,0009,989,00092,966,912
4Jun 24, 2024 20:223,41155,919,75120,026,00011,014,00092,966,912
5Jun 24, 2024 20:223,41563,301,49119,049,00012,031,00092,864,512
6Jun 24, 2024 20:223,41658,155,64020,058,00011,032,00092,913,664
7Jun 24, 2024 20:223,65793,007,17833,275,790094,609,408
8Jun 24, 2024 20:223,67992,519,03333,476,876094,625,792
9Jun 24, 2024 20:223,706112,543,85233,727,265094,613,504
10Jun 24, 2024 20:225,06174,034,48725,029,00021,024,00093,048,832
11Jun 24, 2024 20:225,28572,651,91222,043,00026,051,00093,089,792
12Jun 24, 2024 20:226,95793,778,81224,116,00039,190,00093,290,496