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:24Joad NacerJoad NacerScore: 4,264Success
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:254,06464,745,96126,985,0009,994,00092,925,952
2Apr 22, 2024 00:254,07469,648,19027,053,00010,019,00092,889,088
3Apr 22, 2024 00:254,07658,861,66126,065,00011,027,00092,971,008
4Apr 22, 2024 00:244,08260,386,40825,101,00012,048,00092,938,240
5Apr 22, 2024 00:254,08266,491,27225,097,00012,046,00092,876,800
6Apr 22, 2024 00:244,09360,040,03325,168,00012,080,00092,938,240
7Apr 22, 2024 00:244,11963,973,95427,351,00010,130,00092,893,184
8Apr 22, 2024 00:244,13964,264,71926,759,00010,902,00092,893,184
9Apr 22, 2024 00:254,14264,510,49527,502,00010,186,00092,905,472
10Apr 22, 2024 00:244,14563,300,48826,801,00010,918,00093,011,968
11Apr 22, 2024 00:244,14564,522,00525,806,00011,910,00092,839,936
12Apr 22, 2024 00:254,16162,633,70726,903,00010,960,00092,884,992
13Apr 22, 2024 00:244,264107,447,06238,806,924094,482,432
14Apr 22, 2024 00:254,264131,913,40538,802,636094,482,432
15Apr 22, 2024 00:244,289101,282,79239,031,232094,617,600
16Apr 22, 2024 00:254,294102,978,34039,077,609094,482,432
17Apr 22, 2024 00:244,29699,076,28239,092,961094,490,624
18Apr 22, 2024 00:254,323109,688,12539,337,146094,617,600
19Apr 22, 2024 00:254,37571,723,92025,878,00013,934,00092,954,624
20Apr 22, 2024 00:254,41869,277,23626,133,00014,072,00092,889,088
21Apr 22, 2024 00:254,47567,155,71227,813,00012,913,00092,958,720
22Apr 22, 2024 00:244,70568,214,41627,878,00014,934,00092,880,896
23Apr 22, 2024 00:245,36574,136,64526,901,00021,919,00093,110,272
24Apr 22, 2024 00:245,56776,106,69627,814,00022,847,00093,130,752