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:12Joad NacerJoad NacerScore: 3,812Success
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:113,71459,618,39322,862,00010,934,00092,930,048
2Apr 22, 2024 01:123,71761,664,73022,884,00010,944,00092,938,240
3Apr 22, 2024 01:113,72065,340,28623,595,00010,259,00092,930,048
4Apr 22, 2024 01:123,72962,947,48622,954,00010,978,00092,872,704
5Apr 22, 2024 01:123,73159,942,30622,966,00010,983,00092,938,240
6Apr 22, 2024 01:113,73761,823,34823,002,00011,001,00092,938,240
7Apr 22, 2024 01:123,75364,058,34123,103,00011,049,00092,938,240
8Apr 22, 2024 01:113,76257,226,08323,157,00011,075,00092,958,720
9Apr 22, 2024 01:113,76756,951,69123,189,00011,090,00092,921,856
10Apr 22, 2024 01:123,79558,465,48123,363,00011,173,00092,897,280
11Apr 22, 2024 01:113,79865,929,83923,383,00011,183,00092,897,280
12Apr 22, 2024 01:113,80961,074,43522,779,00011,884,00092,930,048
13Apr 22, 2024 01:113,81259,030,02923,786,00010,902,00092,913,664
14Apr 22, 2024 01:113,81565,903,82523,805,00010,910,00092,868,608
15Apr 22, 2024 01:123,81662,583,02523,814,00010,914,00092,917,760
16Apr 22, 2024 01:124,05895,454,71036,929,411094,482,432
17Apr 22, 2024 01:114,07597,489,00137,086,426094,486,528
18Apr 22, 2024 01:114,077108,862,30037,098,882094,498,816
19Apr 22, 2024 01:124,081100,528,26637,137,007094,605,312
20Apr 22, 2024 01:124,091113,317,35037,226,722094,490,624
21Apr 22, 2024 01:114,09692,335,74037,275,902094,490,624
22Apr 22, 2024 01:125,26477,987,41324,949,00022,953,00093,106,176
23Apr 22, 2024 01:125,69276,351,79624,901,00026,894,00093,110,272
24Apr 22, 2024 01:126,36884,085,53325,978,00031,973,00093,257,728