How to parse JSON from the Enter Data module RRS feed

  • Question

  • I already posted this question as a comment (1) but I thought I would re-post in order to increase the audience since it has been almost 24 hours with no response.  

    Can anyone share how to parse JSON from the Enter Data module?

    I have this data (CSV with header):

    {"client":"Company ABC","totalUSD":7110.0000,"durationDays":731,"familySize":4,"assignmentType":"Long Term","homeLocation":"Australia","hostLocation":"United States","serviceName":"Service XYZ","homeLocationGeoLat":-25.274398,"homeLocationGeoLng":133.775136,"hostLocationGeoLat":37.09024,"hostLocationGeoLng":-95.712891}

    And this to parse it:

    install.packages("src/rjson_0.2.15.zip", lib = ".", repos = NULL, verbose = TRUE)

    library(rjson, lib.loc=".", verbose=TRUE)

    data <- fromJSON(json_str = as.character(dataset1$json), method = 'C')

    df <- as.data.frame(data)

    But I get this error:

     incomplete list

    How can I parse JSON from the Enter Data module?

    As an aside, are there any plans to parse JSON directly; like a module to convert JSON input into a dataset?  That would be helpful when creating web services.

    1. https://social.msdn.microsoft.com/Forums/azure/en-US/f8d3847a-8b32-4cdb-b500-c6c3946ac67c/json-sample-for-web-service?forum=MachineLearning

    • Edited by _dominic Tuesday, August 18, 2015 2:13 PM
    Tuesday, August 18, 2015 1:37 PM


  • Hi Dominic,

    This approach seems to work, could you try it?

    Here is the sample experiment:

    In the 'Enter Data' module, select DataFormat = TSV, with no headers.

    {"client":"BHP Billiton","totalUSD":7110.0000,"durationDays":731,"familySize":4,"assignmentType":"Long Term","homeLocation":"Australia","hostLocation":"United States","serviceName":"Global Pet Transportation","homeLocationGeoLat":-25.274398,"homeLocationGeoLng":133.775136,"hostLocationGeoLat":37.09024,"hostLocationGeoLng":-95.712891}

    In the 'Execute R Script' module, this is the script I used:

    # Map 1-based optional input ports to variables
    dataset1 <- maml.mapInputPort(1) # class: data.frame
    data <- fromJSON(json_str = as.character(dataset1), method = 'C')
    out <- as.data.frame(data)
    # Select data.frame to be sent to the output Dataset port

    The output is as follows:

    Hope this helps.


    Tuesday, August 18, 2015 3:19 PM