Data Property

Data Property

The data property block is designed to allow you to write Blawx code about object attributes before you have defined those attributes inside the Blawx interface.

In order to allow Blawx to power other applications on the internet, it needs to be able to collect data from those other applications. The Blawx Reasoner API allows you to submit code in a .blawx format, and data in JSON. Blawx then converts the JSON data into object data without categories. These JSON structures will be given a single root object, with the name “data”, and all of the elements of the JSON object will be created as attributes of that object. The sub-objects will not have human-readable names, but can be referred to in variables.

So if you submit the following JSON data package:

 'foo': 'bar'

Blawx will create an object named “data”, with an attribute named ‘foo’, the value of which is set to ‘bar’.

If you submit the following JSON data package:

 foo: {
  'this': 'that',
  'one': 1

Blawx will create an object called data, with an attribute named ‘foo’. It will also create a second object, which will be set as the value of “foo”. That second object will have two attributes, named “this” and “one”, with the values indicated. The second object will not have a human-readable name.

In order for the data to be reasoned over, you need to be able to refer to the attributes of these unnamed objects. You could duplicate your data structure in Blawx by defining all of the categories and attributes in your data, but that would be time consuming, and error-prone. So as a shortcut, the data property block allows you to use any property name you choose.

For example, if you wanted to get the value of ‘one’ in the above data package, and test whether it was more than 5, you would use the following blocks.

Note that the data property block works in exactly the same way as the object property block, except that it allows you to type in the name of a property that may not be defined anywhere. If you type in the name of a property that is defined in a category, it will work as though you had used that property block.

However, it is recommended that you only use the data property block for externally-submitted data. Using the standard object property blocks helps to avoid errors in writing your code caused by typos.

If you put the name of a property that is not defined anywhere in a Category and does not exist in the data, Blawx cannot tell that it was a mistake, and your code will fail silently.

For more information on testing with data, see the help page on data dictionaries.

No Comments

Add your comment