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:45Joad NacerJoad NacerScore: 3,985Success
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:453,79659,931,59724,382,00010,159,00092,889,088
2Apr 22, 2024 01:453,81565,104,51223,482,00011,230,00092,876,800
3Apr 22, 2024 01:453,81564,118,42322,812,00011,902,00092,925,952
4Apr 22, 2024 01:453,82562,716,71422,877,00011,935,00092,864,512
5Apr 22, 2024 01:453,83258,208,73922,917,00011,957,00092,930,048
6Apr 22, 2024 01:453,84363,754,17123,979,00010,990,00093,167,616
7Apr 22, 2024 01:453,985106,661,95936,259,194094,482,432
8Apr 22, 2024 01:453,99395,730,02936,337,665094,490,624
9Apr 22, 2024 01:454,013103,874,31636,513,977094,494,720
10Apr 22, 2024 01:455,85479,914,43626,134,00027,139,00093,093,888
11Apr 22, 2024 01:455,98278,470,28726,210,00028,226,00093,151,232
12Apr 22, 2024 01:456,01780,409,66424,889,00029,867,00093,028,352