In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Set up your security questions now so you can recover your account anytime, just log out and back in to get started. Learn more here
Start Free Trial

General Discussions

Discuss any topics that are not product-specific here.
SOLVED

Support for nested JSON in R client

wf1
5 - Atom

The Alteryx promote-python library supports nested JSON objects:

 

{
"name": { "first_name": "colin", "last_name": "kaepernick" } }

 

This doesn't work in the R client though. The jsonlite package supports nested JSON, but for some reason it is being flattened for the promote request:

 

{
"name.first_name": "colin",
"name.last_name": "kaepernick"
}

 

Is there any reason for flattening the JSON here (and not in python) ?

1 REPLY 1
DavidCo
Alteryx
Alteryx

The reason nested JSON is currently flattened in R and not in Python is because all input JSON to an R model is converted, using jsonlite, to a DataFrame. In order to support requests that have multiple observations attached, the JSON must be flattened to accomodate the 2 dimensional nature of a DataFrame. Additionally, when deploying an R model, the model.predict() function must operate on a DataFrame and not on a list.

 

Python is a bit more flexible in the regard. When input JSON is sent to a Python model, the JSON is converted into a dict or a list, depending on its structure. These data types inherently support nested data and thus the input JSON keys are not flattened. When deploying a python model, the deployed function should operate on a dict or a list depending on the expected input structure.

Labels
Top Solution Authors