Workflow Soluiton

 View Only
  • 1.  Write Object to JSON and Read Object from JSON

    Posted May 05, 2016 02:42 PM

    I've used the "Write Object to XML" and "Read Object from XML" components in the past.

    I can't see an equivalent for JSON.  Does such a thing exist?  

    I know some of the generators can parse json from external web services but what if I want to serialize/de-serialize within my workflow?



  • 2.  RE: Write Object to JSON and Read Object from JSON

    Posted May 06, 2016 04:01 AM

    For writing I think you're going to have to build the JSON yourself with a Scripting component.

    That's how I did it for passing a Username/Password to the Mobility API Login API.

    The REST Generator will work for the Reading since it takes the service and converts it to a data type you can use in WF.



  • 3.  RE: Write Object to JSON and Read Object from JSON

    Posted May 06, 2016 07:54 AM

    I've checked back in an old project and you can set the Request Content to JSON.

    So you could use a Single Value mapping, pass the values you need to a DT then pass that to the REST Generator.

    REST Generator - Request Content.png

    Do you have an example of what you are wanting to achieve?



  • 4.  RE: Write Object to JSON and Read Object from JSON

    Posted May 09, 2016 03:51 AM

    I have a situation where I need to output json to file (and read it in) because the external system I'm interacting with does not have an API I can point a generator at.  I can generate a passable json file with a merge text component but thats a little clumsy and needs extra work to deal with illegal characters for json.  Reading in is also possible but very prone to problems.  

    I was hoping for a more elegant solution.  Perhaps a scripting component and powershell (the convertto-json cmdlet) might be worthy of some attention.



  • 5.  RE: Write Object to JSON and Read Object from JSON

    Posted May 13, 2016 08:58 AM

    If memory servers, the scripting component can use javascript, so why not use the JSON.stringify() and JSON.parse() methods?



  • 6.  RE: Write Object to JSON and Read Object from JSON

    Posted May 13, 2016 09:29 AM

    It's

    • C#
    • VB.NET
    • JScript 

    You can do this with the Scripting component:

     

    Namespace

    System.Web.Script.Serialization

    Then in the Source Code section, replace obj with your value you could pass in:

    var json = new JavaScriptSerializer().Serialize(obj);
    return json;

    I tested it with the ADUser DT, that was passed in as a parameter then used in place of obj and it returned:

    {"Guid":null,"Name":null,"FirstName":null,"Initials":null,"LastName":null,"EmailAddress":null,"DisplayName":null,"Description":null,"Office":null,"TelephoneNumber":null,"TelephoneNumberAdditionalList":null,"USNChanged":0,"WebPage":null,"AccountControl":0,"Assistant":null,"Changed":"\/Date(-62135596800000)\/","CommonName":"Alex","Created":"\/Date(-62135596800000)\/","Department":null,"DistinguishedName":null,"Path":null,"CellPhone":null,"EmployeeID":null,"FullDisplayName":null,"HomePhone":null,"MiddleInitial":null,"Notes":null,"POBox":null,"ZipCode":null,"WebPageAdditionalList":null,"MemberOf":null,"MemberOfDn":null,"MembersDn":null,"Street":null,"PostOfficeBox":null,"City":"","State":null,"PostalCode":null,"CountryCode":null,"CountryA2":null,"CountryName":null,"UserLogonName":null,"MiddleName":null,"HomeDirectory":null,"HomeDrive":null,"EmployeeId":null,"UserPrincipalName":null,"SamAccountName":null,"AllowReversiblePasswordEncryption":false,"UserCannotChangePassword":false,"ScriptPath":null,"PasswordNotRequired":false,"PasswordNeverExpires":false,"StorePasswordUsingReversibleEncription":false,"SmartcardLogonRequired":false,"AccountIsDisabled":false,"AccountExpirationDate":null,"LastModifiedDate":null,"AccountIsTrustedForDelegation":false,"ProfilePath":null,"LogonScript":null,"HomeFolder":null,"HomePhoneNumberAdditionalList":null,"Pager":null,"PagerAdditionalList":null,"MobilePhoneNumber":null,"MobilePhoneNumberAdditionalList":null,"FaxNumber":null,"FaxNumberAdditionalList":null,"IpPhone":null,"IpPhoneAdditionalList":null,"PhoneNotes":null,"OrganizationTitle":null,"OrganizationDepartment":null,"Company":null,"Manager":null,"EmployeeNumber":null,"EmployeeType":null}

     



  • 7.  RE: Write Object to JSON and Read Object from JSON

    Posted May 13, 2016 09:42 AM

    https://www-secure.symantec.com/connect/articles/using-rest-generator-response-content-workflow-76

    They added the option to "Create From Sample"

    REST Generator - 2 Components - Response Content.png

    That would make the DT for you, then you can read a file using scripting:

    public void LoadJson()
    {
        using (StreamReader r = new StreamReader("file.json"))
        {
            string json = r.ReadToEnd();
            List<NEWDT> items = JsonConvert.DeserializeObject<List<NEWDT>>(json);
        }
    }

    Replacing NEWDT with the name of your DT.



  • 8.  RE: Write Object to JSON and Read Object from JSON
    Best Answer

    Posted May 16, 2016 11:34 AM


  • 9.  RE: Write Object to JSON and Read Object from JSON

    Posted May 16, 2016 03:54 PM

    Wow what a great response - thanks Alex!



  • 10.  RE: Write Object to JSON and Read Object from JSON

    Posted May 17, 2016 04:52 AM

    Happy to help :)