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 listJul 10, 2024 16:44Joad NacerJoad NacerScore: 3,624Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 10, 2024 16:443,41958,215,10021,078,00010,037,00092,925,952
2Jul 10, 2024 16:443,43557,585,67120,164,00011,090,00093,077,504
3Jul 10, 2024 16:433,44553,892,32821,237,00010,113,00092,901,376
4Jul 10, 2024 16:433,48757,322,33019,835,00011,901,00092,930,048
5Jul 10, 2024 16:433,48857,667,86919,840,00011,904,00092,962,816
6Jul 10, 2024 16:433,50257,703,83419,919,00011,951,00092,983,296
7Jul 10, 2024 16:433,51159,836,94019,966,00011,980,00092,864,512
8Jul 10, 2024 16:443,51462,095,75520,984,00010,991,00092,934,144
9Jul 10, 2024 16:443,51557,045,28920,989,00010,994,00092,905,472
10Jul 10, 2024 16:433,60595,623,48332,804,469094,486,528
11Jul 10, 2024 16:443,60797,090,23532,823,514094,486,528
12Jul 10, 2024 16:443,62299,316,37132,958,431094,486,528
13Jul 10, 2024 16:443,624101,210,52032,975,263094,486,528
14Jul 10, 2024 16:433,629105,566,48433,021,769094,617,600
15Jul 10, 2024 16:433,64893,141,65433,194,913094,490,624
16Jul 10, 2024 16:434,39967,298,39321,016,00019,015,00093,200,384
17Jul 10, 2024 16:444,48667,884,13720,911,00019,916,00093,155,328
18Jul 10, 2024 16:445,09973,111,32922,190,00024,208,00093,057,024
19Jul 10, 2024 16:436,45987,776,58922,913,00035,864,00093,261,824
20Jul 10, 2024 16:447,13899,391,14923,983,00040,971,00093,200,384
21Jul 10, 2024 16:437,25591,256,59025,007,00041,012,00093,347,840
22Jul 10, 2024 16:447,35899,305,45724,985,00041,975,00093,179,904
23Jul 10, 2024 16:437,53997,677,01225,222,00043,383,00093,204,480
24Jul 10, 2024 16:447,584101,061,93624,005,00045,010,00093,270,016