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:46Joad NacerJoad NacerError
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:4600000Error: unexpected EOF
2Apr 22, 2024 01:4700000Error: unexpected EOF
3Apr 22, 2024 01:4700000Error: unexpected EOF
4Apr 22, 2024 01:4700000Error: unexpected EOF
5Apr 22, 2024 01:463,955103,980,97435,991,383094,490,624
6Apr 22, 2024 01:473,95893,575,30336,013,581094,486,528
7Apr 22, 2024 01:473,95998,467,12836,029,155094,486,528
8Apr 22, 2024 01:473,965110,946,59236,079,619094,478,336
9Apr 22, 2024 01:473,97089,159,60536,129,229094,490,624
10Apr 22, 2024 01:463,973107,611,86436,153,829094,490,624
11Apr 22, 2024 01:473,97492,741,35936,160,900094,482,432
12Apr 22, 2024 01:473,975103,222,58936,176,523094,490,624
13Apr 22, 2024 01:473,985112,813,55736,266,331094,486,528
14Apr 22, 2024 01:473,997112,361,19836,372,349094,478,336
15Apr 22, 2024 01:464,000110,242,46136,397,911094,486,528
16Apr 22, 2024 01:474,014101,166,99636,530,560094,486,528