Default usage of SPXmlToJson() (no options) returns array with empty objects

Sep 9, 2012 at 5:09 AM

Hi Mark.

Just got the need to use the SPXmlToJson() utility introduced with 0.7.1 and got stuck trying to make it work... I kept reading the documentation (including copy & Paste of the example there) and re-checking my code until I finally dove into the source of it.

As defined, this utility will return an array of empty objects if no input parameters are defined. The documentation says the following should work (and in my assumption, it should have returned an equivalent of the xml node):

$(xData.responseXML).SPFilterNode("z:row").SPXmlToJson();

But I kept getting an array with empty objects.   I had to set the 'includeAllAttrs' to true in order to have it turn data in the objects.

In reading the documentation, it is not clear that the default input parameters will actually return nothing.  I would have expected that 'includeAllAttrs' would default to true.  The 'mapping' option is also not clear. Initially I thought it was just a mechanism for renaming the attributes and setting their value's data type, but I think it is first and foremost a filter on what actually is returned.

Should the documentation be updated?

Paul

 

Ps. Sorry I did not give you feedback on this utility back when you initially introduced it in Beta.

 

Coordinator
Sep 11, 2012 at 8:35 PM

Paul:

I just added a note to includeAllAttrs saying that its default is false. How else could I improve the docs? It does say that "The default value for mapping is {} (no mappings).", too. It made sense to me when I wrote it, but I'm sure it could be improved!

M.

Sep 12, 2012 at 2:25 AM
Thank for the response Marc.
Perhaps I had the wrong impression. I was expecting that the default behavior would be for it to give you back an exact copy of the input object set in JSON format and that the options would manipulate it to return something else.
My only suggestion would be to clarify that if called with no input parameters defined, then the default option will cause an array of empty objects to be returned. I would also alter the first example under the 'Examples' section (which currently shows no input params defined) to at least include the 'includeAllAttr' option. Without it, it's really not a working example because the return value will always be an array of possible empty objects.
Now that I'm looking at it again, I think this was the item that confused me the most. The text after the first example goes on to say that 'In most cases, you'll pass in options...' which implies that it can be called with not options at all.


_____
Paul

Sent from mobile device.


On Sep 11, 2012, at 3:35 PM, sympmarc <notifications@codeplex.com> wrote:

From: sympmarc

Paul:

I just added a note to includeAllAttrs saying that its default is false. How else could I improve the docs? It does say that "The default value for mapping is {} (no mappings).", too. It made sense to me when I wrote it, but I'm sure it could be improved!

M.