I wouldn't expect you'd need an exact 1:1 mapping of xml elements to json 
objects. The json type may be able to collapse some of that. In the case of 
multiple repeating elements, how about something like this? (There is no 
"engine" because "engines" is an array. Assuming <engines> doesn't contain 
anything other than <engine>.)

{
  "engines": [
     { "version": ">=3.2.0",
       "name": "cordova-android"
     },
     { "version": ">=3.0.0",
       "name": "cordova-ios"
     }
  ]
}

On Feb 15, 2014, at 1:56 PM, Dick Van den Brink <d_vandenbr...@outlook.com> 
wrote:

> I like the idea of json config files but how to handle cases where a element 
> can occur multiple times? With only one element, it would generate an object, 
> but with multiple elements it would change into an array. This might make the 
> code which reads the config a bit more difficult/error prone because it needs 
> to check the type everytime.
> What do you guys think? Or is this a non-issue? Btw, I took a part of a 
> plugin.xml as an example.
> Xml:
> <engines>
>    <engine name="cordova-android" version=">=3.2.0" />
>    <engine name="cordova-ios" version=">=3.0.0" />
> </engines>
> Jason (array because engine element is found multiple times):
> {
>  "engines": {
>    "engine": [
>      {
>        "-version": ">=3.2.0",
>        "-name": "cordova-android"
>      },
>      {
>        "-version": ">=3.0.0",
>        "-name": "cordova-ios"
>      }
>    ]
>  }
> }
> 
> Or json with only one engine in the xml (so an object)
> "engine": {
>  "-version": ">=3.2.0",
>  "-name": "cordova-android"
> }

Reply via email to