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 01:37Joad NacerJoad NacerScore: 3,951Success
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 01:363,75360,290,13424,105,00010,043,00092,872,704
2Apr 22, 2024 01:363,75659,306,55323,123,00011,058,00092,987,392
3Apr 22, 2024 01:373,77956,601,33123,263,00011,126,00092,909,568
4Apr 22, 2024 01:373,78057,789,97123,272,00011,130,00092,884,992
5Apr 22, 2024 01:363,78363,320,64724,301,00010,125,00092,909,568
6Apr 22, 2024 01:363,79459,770,88524,370,00010,154,00092,925,952
7Apr 22, 2024 01:363,80260,810,64222,737,00011,863,00092,905,472
8Apr 22, 2024 01:373,80459,440,61423,736,00010,879,00092,987,392
9Apr 22, 2024 01:363,80865,071,30623,763,00010,891,00092,848,128
10Apr 22, 2024 01:373,81366,232,80622,800,00011,895,00092,880,896
11Apr 22, 2024 01:373,81660,613,91723,810,00010,913,00092,954,624
12Apr 22, 2024 01:373,81860,235,22823,823,00010,918,00092,938,240
13Apr 22, 2024 01:373,95192,673,55135,949,982094,621,696
14Apr 22, 2024 01:373,95994,273,69336,022,911094,482,432
15Apr 22, 2024 01:363,96494,057,93236,072,060094,482,432
16Apr 22, 2024 01:363,96789,122,82336,095,180094,490,624
17Apr 22, 2024 01:373,98291,710,76636,234,071094,490,624
18Apr 22, 2024 01:363,983108,740,02536,242,240094,494,720
19Apr 22, 2024 01:374,36067,212,91123,807,00015,871,00093,118,464
20Apr 22, 2024 01:374,39171,234,93323,975,00015,983,00093,179,904
21Apr 22, 2024 01:374,70767,353,29623,907,00018,926,00093,118,464
22Apr 22, 2024 01:364,83971,661,88524,020,00020,017,00093,167,616
23Apr 22, 2024 01:364,88369,840,13524,236,00020,196,00093,130,752
24Apr 22, 2024 01:366,03980,472,23224,979,00029,975,00092,995,584