Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Geoff Beaumont 75 posts 104 karma points
    Sep 21, 2016 @ 14:09
    Geoff Beaumont
    0

    JSON string converted to [object Object]

    Hi Richard,

    I've run into an issue with CMSImport trashing data that I can't find any workaround for - we have a Textbox field on Members which is used to store a JSON string (it doesn't need to be anything fancier than that).

    This all works fine normally, but when importing member data using CMSImport what appears in that field is "[object Object]". It looks like CMSImport is parsing it into an object and then doing ToString() on it! I can't see any way to tell CMSImport that a string really is just a string and should be left alone? I'd have hoped that when importing the data into a Textbox CMSImport wouldn't attempt to manipulate it in any way?

    In case it's at all relevant, the data is being imported from an Excel file (it's exported using your MemberExport package).

    Incidentally - there's also a bug in the Excel import. If the Excel file contains no sheet named "sheet1" you get an error and can't proceed (even though it then lets you select which sheet to import data from). MemberExport creates a spreadsheet with a single sheet named (IIRC) MemberExport, so it's necessary to open it in Excel and rename the sheet before it can be imported.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 21, 2016 @ 15:13
    Richard Soeteman
    0

    Hi Geoff,

    The excel is after you modified a sheet? That is a nasty one and will be fixed.

    CMSImport is always converting to the type of field in the database and an object is used to get it from the reader.

    Best,

    Richard

  • Geoff Beaumont 75 posts 104 karma points
    Sep 21, 2016 @ 15:46
    Geoff Beaumont
    0

    Hi Richard,

    No, I only edited the exported data to change the sheet name so I could import it - I was trying to use it directly from MemberExport.

    How do I import JSON data then? It's just a string, as far as Umbraco is concerned, but CMSImport is obviously recognising it as parseable into an object and doing that, but then just using ToString() to render it back to a string for Textbox. Surely when importing to a text field it should leave the content it receives alone and not attempt to turn it into an object?

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Sep 21, 2016 @ 15:48
    Nicholas Westby
    0

    http://issues.umbraco.org/issue/U4-7382

    Umbraco bug. There are some clumsy workarounds, including prefixing the JSON string with something so it doesn't look like JSON, then removing that prefix when you need the data.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 22, 2016 @ 06:31
    Richard Soeteman
    0

    Thanks for posting the workaround, maybe you can add that to your sheet Geoff?

  • Geoff Beaumont 75 posts 104 karma points
    Sep 22, 2016 @ 10:37
    Geoff Beaumont
    0

    Thanks Nicholas - that's very useful!

    That would have caused problems sooner or later anyway in this case, regardless of CMSImport (I'd changed the field to Textbox as it was set to ContentPicker, but the the data format had been made more complex and was no longer actually compatible with ContentPicker - when CMSImport imported it it tried to transform it into ContentPicker data which, not surprisingly, didn't work. I'd hoped Textbox would mean it would just be left as a text string! I suspect it would still have saved okay from the custom code that uses it, as that wasn't objecting to the conflict with ContentPicker, but if the member was edited in the back office it likely wouldn't have gone so well in either case!

    Richard - yes, in this case I can work around the issue by prefixing the values as Nicholas suggests, and stripping them in the calling code.

  • Geoff Beaumont 75 posts 104 karma points
    Sep 22, 2016 @ 11:03
    Geoff Beaumont
    0

    I can confirm that adding a prefix ("-" in my case) to the JSON data in the spreadsheet results in it being imported unmolested.

Please Sign in or register to post replies

Write your reply to:

Draft