From 20a6261eb1161e6a824b447ed8aae7e6e1acaf13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Blanchon?= Date: Mon, 30 Nov 2015 22:23:57 +0100 Subject: [PATCH] Updated FAQ (markdown) --- FAQ.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/FAQ.md b/FAQ.md index 4d81c0f..206fabc 100644 --- a/FAQ.md +++ b/FAQ.md @@ -2,6 +2,31 @@ See [Compatibility issues](Compatibility issues) first. +### Should I call `parseArray()` or `parseObject()`? + +This is a very common question as people are often confused when the JSON input contains mixed arrays and objects. + +The answer is very simple: it's the type of the root that matters. +This means that you just need to look at the first character: it's either a `[`, for an array, or a `{`, for an object. + +For example, if the input is: + +```json +{"mickey":["mouse"],"donald":["duck"]} +``` + +then you must call `parseObject()` because the root is an object. + +And, if the input is: + +```json +[{"mickey":"mouse","donald":"duck"}] +``` + +then you must call `parseArray()` because the root is an array. + +Finally, if you cannot know in advance the type of the root, please open an issue. Don't worry this can be implemented very easily, it's just that nobody asked for it. + ### Why parsing fails? The parsing functions, `parseArray()` and `parseObject()`, may fail for 3 reasons: