SMS2 Formatting for arrays

I have a JSON document that I want to transform into triples. Among the JSON elements is an element that contains a set of arrays, in roughly this format:

  • ID
  • Name
  • Contact
    -- Telephones (array)
    -- Email address (array)
    -- Websites (array)
    -- Twitter (array)

I can describe the FROM JSON mappings for the two simple JSON elements, but not sure what the SMS2 encoding for the Contact JSON element that contains a list of arrays. My attempts so far yield parsing errors.

Your thoughts?

Hi Tom,

You can specify arrays in the mapping source using the square brackets as normal. If they're scalar, specify a variable name in quotes. If they're object, then you should nest the object fields, eg.

  "email_addresses":[ { "email_address":"?email_address", "source":"marketing" } ]

Each element in the array will produce one binding for the variable(s) in the array.


Hi Tom,

For your example, you can try the following:

	"ID": "?ID" ,
    "Name": "?Name" ,
			{"value": "?phone"}
			{"value": "?email"}
			{"value": "?webSite"}
			{"value": "?twitter"}


Jess and Daniel, thanks for your help! I was able to resolve my issue with your advice. Is there more documentation that describes SMS options? For example, I want to append a random number to an IRI for each instance of an array, defined in the WHERE clause of the SMS script. For example:

where 123456 is the customer ID, one of the values in an array, while 4930 and 0173 is a random number generated through the SMS script.

My current WHERE clause includes the following to generate all but the random suffix:

bind(template("{?id} ") as ?custaddrIRI)

How can I revise this statement to add a random number to the IRI?

Thank you!

Hi Tom,

I know two ways to generate a random value but they are really different.


The first one is the bnode function. That function generates everytime a random, unique and new blank node. You can use it as IRI. You use the bnode function in a bind and the syntax is simply

bind(bnode() as ?blankNode)


The second one is the rand function that generate a random number between 0 and 1. But the result is not unique. Be careful about that. You also use it in a bind as in:

bind(rand() as ?randomNumber)

Also, as that second option does not generate a complete IRI and you need to do the assembly with something else as:

bind(concat(?customerId, "-", ?randomNumber) as ?shortIRI)

And after that, you use the template function as you are right now. But remember, the generated number is not unique.


If you really don't care about the generated IRI, you should use the bnode function. You can count on it to generate something unique.

You can also use a part of your address to generate a hash value and use it to complete your IRI.
The following code will generate a nice GUID you can use:

BIND(replace(md5(?mergedAddressFields),"^(\\w{8})(\\w{4})(\\w{4})(\\w{4})",'$1-$2-$3-$4-') as ?guid) 

But I wouldn't use the rand function as the value is not unique.

Re: random numbers, there're also uuid/struuid.


1 Like

Thank you, Daniel, for a very comprehensive answer. Much appreciated.

Thanks Pavel. I'll look into them.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.