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:32Joad NacerJoad NacerScore: 4,010Success
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:323,78357,682,81124,298,00010,124,00092,938,240
2Apr 22, 2024 01:323,78555,803,70924,311,00010,129,00092,897,280
3Apr 22, 2024 01:313,78655,363,15525,335,0009,120,00092,921,856
4Apr 22, 2024 01:323,78656,974,78724,320,00010,133,00092,921,856
5Apr 22, 2024 01:313,78761,409,58224,325,00010,135,00092,925,952
6Apr 22, 2024 01:313,82061,031,33923,834,00010,924,00092,889,088
7Apr 22, 2024 01:313,82160,974,09422,847,00011,920,00092,930,048
8Apr 22, 2024 01:323,83163,613,78322,908,00011,952,00092,934,144
9Apr 22, 2024 01:313,83459,756,56522,926,00011,961,00093,159,424
10Apr 22, 2024 01:323,83961,812,37822,958,00011,978,00092,925,952
11Apr 22, 2024 01:313,85463,593,92223,045,00012,023,00092,917,760
12Apr 22, 2024 01:323,85763,406,26624,067,00011,031,00092,901,376
13Apr 22, 2024 01:314,01093,101,00736,489,882094,482,432
14Apr 22, 2024 01:324,023108,734,96836,612,282094,482,432
15Apr 22, 2024 01:314,030117,215,45636,671,919094,490,624
16Apr 22, 2024 01:314,03098,045,25436,669,070094,490,624
17Apr 22, 2024 01:324,037104,442,54336,737,884094,490,624
18Apr 22, 2024 01:324,040104,730,82236,765,334094,482,432
19Apr 22, 2024 01:315,13571,422,04924,854,00021,872,00093,179,904
20Apr 22, 2024 01:315,53978,553,42925,201,00025,201,00093,007,872
21Apr 22, 2024 01:325,66480,800,05126,277,00025,266,00093,147,136
22Apr 22, 2024 01:326,04878,245,34825,019,00030,022,00093,184,000
23Apr 22, 2024 01:326,10380,205,96326,256,00029,285,00093,204,480
24Apr 22, 2024 01:316,42785,812,49328,235,00030,252,00093,097,984