Get grouped data value from kobotoolbox

Say that the body of a message received from Kobotoolbox is similar to this one:

{
“__query_params”: {},
“data”: {
“_id”: 164066146,
“group_fields/code1”: “code number one”,
“group_fields/code2”: “code number two”,
}
}

I know that state.data.data._id retrieves the value of “_id”.
But to get the value of that “g_update/code”?
Thanks in advance.

Hi @kumori, if you’re trying to access this data in an OpenFn job, you’d use bracket notation (see “property accessors”) like this:

create('thing', {
  id: dataValue('data.id'), // the best way
  id: state.data.data._id, // or like this
  id: state['data']['data']['_id'], // or this
  code: dataValue('data.group_fields/code1'), // the best way
  code: state.data.data['group_fields/code1'] // or like this
  code: state.data.data['g_update/code'], // or this
});

Hope that helps!

Taylor

1 Like