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 listApr 22, 2024 00:17Joad NacerJoad NacerScore: 3,928Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 00:173,82561,629,47223,865,00010,938,00092,876,800
2Apr 22, 2024 01:013,83267,735,14623,909,00010,958,00092,897,280
3Apr 22, 2024 01:013,83561,159,30923,933,00010,969,00092,942,336
4Apr 22, 2024 01:013,84165,521,82623,966,00010,984,00092,893,184
5Apr 22, 2024 01:013,84762,976,59724,004,00011,001,00092,962,816
6Apr 22, 2024 00:173,85356,383,03223,038,00012,020,00092,946,432
7Apr 22, 2024 00:173,87361,827,34824,170,00011,078,00092,880,896
8Apr 22, 2024 00:173,87461,959,60723,167,00012,087,00092,893,184
9Apr 22, 2024 01:013,89063,056,97224,271,00011,124,00092,934,144
10Apr 22, 2024 00:173,89666,949,95624,311,00011,142,00092,876,800
11Apr 22, 2024 01:013,90464,383,77225,376,00010,150,00092,934,144
12Apr 22, 2024 00:173,91760,022,29624,442,00011,202,00092,934,144
13Apr 22, 2024 01:013,92859,181,12223,828,00011,914,00092,889,088
14Apr 22, 2024 01:013,92862,802,80824,825,00010,923,00092,917,760
15Apr 22, 2024 00:174,01367,074,31224,343,00012,171,00092,942,336
16Apr 22, 2024 01:014,029104,753,29236,667,629094,482,432
17Apr 22, 2024 00:174,040103,955,69436,767,396094,494,720
18Apr 22, 2024 01:014,045103,231,83636,811,421094,478,336
19Apr 22, 2024 00:174,04699,496,34736,815,850094,486,528
20Apr 22, 2024 01:014,063107,316,00936,977,801094,486,528
21Apr 22, 2024 00:174,07894,368,31037,109,326094,609,408
22Apr 22, 2024 00:174,50166,485,48723,975,00016,982,00092,921,856
23Apr 22, 2024 01:015,46576,822,27624,867,00024,867,00093,147,136
24Apr 22, 2024 00:176,18489,602,73127,130,00029,140,00093,102,080