+ Reply to Thread
Results 1 to 16 of 16

Convert Object to JSON String

  1. #1
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Convert Object to JSON String

    Hello guys,

    I have a procedure that converts a JSON String into an Object. This has been working just great for years and I don't have a problem with that. NOW, I want build exactly the opposite. I want to build a JSON String out of personalized Object created from a class.

    Is there a way to do it? Do you guys have a sample that can show me?

    Appreciate your help,
    1 Or 0, that is the question.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Convert Object to JSON String

    Well, two things:
    1. What is A JSON string?
    2. Could you please attach a sample workbook.

    Maybe a workbook isn't necessary depending on what the definition of a JSON string is.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Convert Object to JSON String

    JSON String is the full text that represent the JSON Object.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Convert Object to JSON String

    More likely to get some ideas from

    http://ramblings.mcpher.com/Home/exc...ks/classeslink

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Convert Object to JSON String

    I normally don't use json. I just get a string from a web service and then parse it.

    This might have something for you. http://ramblings.mcpher.com/Home/excelquirks/json

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Convert Object to JSON String

    This meant

    http://ramblings.mcpher.com/system/a...ch-site&q=JSON

    I have never played with JSON as it does not work with excel 64 bits

  7. #7
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Convert Object to JSON String

    Thank you @AB33. I already looked there and yes, there are some things that can be considered.

  8. #8
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Convert Object to JSON String

    I usually get the string and parse it out in VBA into an Object. But now I need to get the Object in VBA and parse it into a String.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Convert Object to JSON String

    What's the object?

  10. #10
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Convert Object to JSON String

    Personalized class object with properties that I built myself.

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Convert Object to JSON String

    You'll need to serialize it manually, there's no reflection built into vba so you can't get the properties at runtime

  12. #12
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Convert Object to JSON String

    You'll need to serialize it manually
    What you mean? Put it in a dictionary/collection?

  13. #13
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Convert Object to JSON String

    Sort of, I think you'll need to map your object to dictionaries and arrays, you can then use the code here to convert it to JSON

    https://github.com/VBA-tools/VBA-JSO...nConverter.bas

  14. #14
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Convert Object to JSON String

    A THOUSAND LINES OF CODE!!! That looks like an easy task to go through... Thank you!!!

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Convert Object to JSON String

    You don't need to go through it, just stick it in a module and call the function

  16. #16
    Forum Contributor amartinez988's Avatar
    Join Date
    05-04-2015
    Location
    Miami
    MS-Off Ver
    Office 2010
    Posts
    183

    Re: Convert Object to JSON String

    I was just going through the code and it's great. I think I can work with this. You and whoever wrote this. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as shown in
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-28-2016, 11:49 AM
  2. Replies: 11
    Last Post: 05-23-2016, 07:42 AM
  3. Possible to convert IE object into HTTPReqest object in web scrapping?
    By lubbamkt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2016, 02:01 PM
  4. Reference an object via a string (Convert a string to an objejct reference
    By grazian2 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-16-2015, 11:47 AM
  5. Get all elements from a json object at once
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2015, 02:34 AM
  6. Is there a native way to encode an object as a JSON string?
    By XmisterIS in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-01-2014, 05:32 AM
  7. Convert object as string
    By LTA in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-22-2010, 09:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1