godot: Dictionary fails to parse JSON with array as top level

Operating system or device: Ubuntu 15.10 64bits

Issue description (what happened, and what was expected): It’s valid for a JSON to have an array as top level, however Dictionary fails to parse it:

ERROR: parse_json: Error parsing JSON: Expected '{' at line: 0
   At: core/dictionary.cpp:206.

Steps to reproduce:

func test_json_top_level_array():
    assert({}.parse_json("[ { \"name\": \"Richard\" }, {\"name\": \"Drahcir\"} ]") == OK)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 22 (19 by maintainers)

Most upvoted comments

@mooglegiant A valid JSON can have an array [] as top level.

The problem is that a Dictionary needs a key (otherwise it would be an Array). IMO the best solution would be to expose a JSON class to GDScript with a parse method that would return either an Array or a Dictionary.

@reduz WDYT?