locked
Conversion of XML element with a space to JSON RRS feed

  • Question

  • How do I convert a XML element with only  a space to a JSON tag with a space.

    The BizTalk 2013R2 JSON encoder pipeline converts this XML

    <test>
    <quotes>" "</quotes>
    <space> </space>
    </test> 

    to

    {
      "quotes": "\" \"",
      "space": null
    }

    I want "" not null as shown below

    {
      "quotes": "\" \"",
      "space": ""
    }

    Wednesday, December 23, 2015 11:03 PM

Answers

All replies

  • Hi Mark,

    Thank you for posting on MSDN forum.

    Please have a look into below thread,

    http://stackoverflow.com/questions/24368006/how-to-get-json-net-to-serialize-empty-xml-element-to-empty-string


    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    • Proposed as answer by Angie Xu Tuesday, January 5, 2016 6:04 AM
    • Marked as answer by Angie Xu Tuesday, January 5, 2016 6:04 AM
    Thursday, December 24, 2015 3:55 AM
    Moderator
  • You can look into below article too, same question has been discussed

    https://connectedpawns.wordpress.com/2015/12/24/rest-json-christmas-puzzle/


    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    Thursday, December 24, 2015 7:02 AM
    Moderator
  • Unfortunately, this behavior is not configurable with the oob JSON encoder.

    That means you will have to investigate a custom solution.

    The BizTalk JSON component is based on Json.Net which can be found here: https://github.com/JamesNK/Newtonsoft.Json

    Thursday, December 24, 2015 3:31 PM
    Moderator
  • Hi Mark - like others have mentioned, the Json encoder uses the Newtonsoft.Json library to do the conversion.

    In the execute method, it calls the static JsonConvert class with these parameters:

    JsonConvert.SerializeXmlNodeToStream(xmlDocument, 1, this.RemoveOuterEnvelope, true, true, matchingSchema);

    The method SerializeXmlNodeToStream isn't in the current version of the Newtonsoft.Json library - I can't find it looking at the code for this class here: https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/JsonConvert.cs

    Looking at the Newtonsoft.Json assembly obtained from the GAC on a BizTalk 2013 R2 machine however, the assembly version is 4.5.1.17203.  The solution on GitHub is tagged nicely but this method doesn't exist in version 4.5.1 - I think therefore that the version used by BizTalk is a (Microsoft) fork of the main code branch.

    So I think the best option for you would be to write your own pipeline component using the Newtonsoft.Json library with the behaviour that you want.

    Cheers,

    James.

    Friday, December 25, 2015 9:05 AM