0

We're sending out a chunk of json to node/faye and having some issues with nested arrays. Here is the json:

{
    "event_189420": {
        "num_horses": 11,
        "sport_name": "horse",
        "conditions": "",
        "ort": 13,
        "result_4": [],
        "sis": "",
        "fixed_odds": false,
        "event_class": "Attele - Course G (trot)",
        "event_desc": "Prix de L'U.N.A.T.",
        "non_runners": "",
        "event_id": 189420,
        "tek": "",
        "distance": "2650m",
        "good_result_count": 0,
        "result_prices": {},
        "result_1": [],
        "ticker": "",
        "prize": "6000 EUR",
        "result_2": [],
        "race_name": "Bordeaux Le Bouscat",
        "big_screen": true,
        "horses": [
            [
                "Qu'Il Vive del Sol",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Rocky du Bordage",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Reve",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Rafale des Racques",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Releve du Liard",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Nichtstarter",
                false,
                "****",
                "****",
                "",
                "",
                "",
                "",
                true,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Rire Eclatant",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Quinquin",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Pacific d'Yvel",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Romain de Godisson",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ],
            [
                "Rhapsodie Models",
                false,
                "",
                "999",
                "",
                "",
                "",
                "",
                false,
                "",
                false,
                false,
                "OK"
            ]
        ],
        "starting_time": "16:10",
        "result_3": [],
        "race_status": "open",
        "small_screen": true,
        "pmsg": "",
        "race_num": 8
    }
}

As you can see there are a lot of 'empty' elements (just ""). For the 'top level' object this is fine, we get 'key': ''. But, for the sub array (in this case 'horses') the "" elements are simply removed.

This must be happening on the client side - everything we see on the server side looks ok. Even using static json pulled from a file exhibits the same behaviour on the client.

Are we doing something wrong or is this an issue with node/faye?

KARASZI István
  • 30,900
  • 8
  • 101
  • 128
phil
  • 4,668
  • 4
  • 33
  • 51

1 Answers1

-1

If you need to create a placeholder in the array, use NULL instead of an empty string.

srquinn
  • 10,134
  • 2
  • 48
  • 54
  • I could not find any reference to empty strings being ignored; JSON test suites across the net do not ignore them, as well as V8's `JSON.parse`. – lanzz Jun 06 '12 at 12:22
  • What browser are you testing in? IE doesn't behave as expected when using JSON.parse and encountering empty strings. See this discussion http://stackoverflow.com/questions/1543791/json-empty-string – srquinn Jun 06 '12 at 14:02
  • Chrome — no problem stringifying or parsing empty strings. The question you talk about appears to discuss _seemingly_ empty strings which actually fail encoding conversion, thus resulting in null values in the JSON. The grammar at http://www.json.org/ explicitly states that strings can be zero-length and does not limit what strings can appear as values in arrays. – lanzz Jun 06 '12 at 14:05
  • I am forced to use IE, unfortunately. This is still happening, but we've resorted to a placeholder. – phil Nov 25 '12 at 06:04