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:22Joad NacerJoad NacerScore: 3,879Success
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:213,80560,040,46524,444,00010,185,00093,220,864
2Apr 22, 2024 01:223,82162,370,49422,850,00011,922,00092,901,376
3Apr 22, 2024 01:223,82263,351,41123,848,00010,930,00092,934,144
4Apr 22, 2024 01:213,82660,119,86222,878,00011,936,00092,934,144
5Apr 22, 2024 01:223,82859,916,10122,891,00011,943,00093,216,768
6Apr 22, 2024 01:213,83570,211,64423,931,00010,968,00092,913,664
7Apr 22, 2024 01:213,83560,961,07722,932,00011,964,00092,901,376
8Apr 22, 2024 01:213,83860,712,47923,951,00010,977,00093,020,160
9Apr 22, 2024 01:223,84163,136,57922,968,00011,983,00092,909,568
10Apr 22, 2024 01:223,84458,119,86723,988,00010,994,00093,069,312
11Apr 22, 2024 01:223,85162,335,65223,030,00012,015,00092,942,336
12Apr 22, 2024 01:213,85362,293,70723,041,00012,021,00093,147,136
13Apr 22, 2024 01:213,87957,846,54523,196,00012,102,00092,946,432
14Apr 22, 2024 01:213,98393,716,83336,243,849094,617,600
15Apr 22, 2024 01:213,985105,992,36936,264,271094,482,432
16Apr 22, 2024 01:224,017108,532,46936,557,780094,617,600
17Apr 22, 2024 01:214,019106,673,72236,574,863094,490,624
18Apr 22, 2024 01:224,022104,600,25836,599,450094,482,432
19Apr 22, 2024 01:224,02699,260,55436,640,609094,486,528
20Apr 22, 2024 01:214,36966,175,75423,855,00015,903,00092,934,144
21Apr 22, 2024 01:224,97369,879,92525,142,00020,113,00093,184,000
22Apr 22, 2024 01:225,47775,282,73325,919,00023,925,00093,036,544
23Apr 22, 2024 01:225,49275,587,47224,989,00024,989,00093,122,560
24Apr 22, 2024 01:217,23695,123,18225,939,00039,907,00093,335,552