Dataset: How to pass null values?


#1

Hi everybody,

I have the following code to populate dataset with null values but when I execute the script I have te following message: Exception: The supplied value for “webdirectj” is not a number

dataset = client.datasets.find_or_create('soa_florent_test', {
'time':{ 'type': 'datetime', 'name': 'Time'},
'webdirectj-7':{ 'type': 'number', 'name': 'webdirectj-7', 'optional': True},
'webdirectj':{ 'type': 'number', 'name': 'webdirectj','optional': True}
})

#dataset.delete()

dataset.put([
   { 'time': '2018-01-01T12:00:00Z', 'webdirectj-7': 819, 'webdirectj': 812 },
   { 'time': '2018-01-01T13:00:00Z', 'webdirectj-7': 821, 'webdirectj': 815 },
   { 'time': '2018-01-01T14:00:00Z', 'webdirectj-7': 810, 'webdirectj': 819 },
   { 'time': '2018-01-01T15:00:00Z', 'webdirectj-7': 832, 'webdirectj': 818 },
   { 'time': '2018-01-01T16:00:00Z', 'webdirectj-7': 831, 'webdirectj': 811 },
   { 'time': '2018-01-01T17:00:00Z', 'webdirectj-7': 832, 'webdirectj': ''},
   { 'time': '2018-01-01T18:00:00Z', 'webdirectj-7': 820, 'webdirectj': ''},
])

How can I pass null value in JSON (nota I don’t want to replace by 0) ?


#2

Hi @loud,

Numeric types such as number, money and percentage can be NULL if the field is set to “optional” ( e.g. set to optional=true when the numeric field is created).

To pass this type of value in your payload, you’ll want to add NULL to the payload, rather than an empty string.

Here is an example of that using your payload:

dataset.put([
   { 'time': '2018-01-01T12:00:00Z', 'webdirectj-7': 819, 'webdirectj': 812 },
   { 'time': '2018-01-01T13:00:00Z', 'webdirectj-7': 821, 'webdirectj': 815 },
   { 'time': '2018-01-01T14:00:00Z', 'webdirectj-7': 810, 'webdirectj': 819 },
   { 'time': '2018-01-01T15:00:00Z', 'webdirectj-7': 832, 'webdirectj': 818 },
   { 'time': '2018-01-01T16:00:00Z', 'webdirectj-7': 831, 'webdirectj': 811 },
   { 'time': '2018-01-01T17:00:00Z', 'webdirectj-7': 832, 'webdirectj': null },
   { 'time': '2018-01-01T18:00:00Z', 'webdirectj-7': 820, 'webdirectj': null },
]) 

Let us know if you have any other questions!

Best,
Heather