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:19Joad NacerJoad NacerScore: 4,102Success
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:193,90366,081,95124,355,00011,163,00092,860,416
2Apr 22, 2024 01:193,90666,297,68924,372,00011,170,00093,188,096
3Apr 22, 2024 01:193,90760,518,06824,380,00011,174,00092,930,048
4Apr 22, 2024 01:193,92560,744,98724,804,00010,913,00093,085,696
5Apr 22, 2024 01:193,92559,438,06325,516,00010,206,00092,921,856
6Apr 22, 2024 01:193,92661,349,51623,821,00011,910,00093,016,064
7Apr 22, 2024 01:194,10295,040,37737,326,421094,478,336
8Apr 22, 2024 01:194,103100,490,50537,334,165094,756,864
9Apr 22, 2024 01:194,10490,480,66037,349,948094,490,624
10Apr 22, 2024 01:195,15372,150,07024,941,00021,948,00093,134,848
11Apr 22, 2024 01:195,41479,294,54426,143,00023,126,00093,061,120
12Apr 22, 2024 01:196,07279,873,25826,120,00029,134,00093,065,216