# Unclear interaction of SMS2 FROM JSON with arrays

**URL:** <https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522>\
**Category:** Support\
**Created:** [August 4, 2023, 1:26pm UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522 "2023-08-04T13:26:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boris\_Pelakh](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/boris_pelakh/32/1890_2.png) [@Boris\_Pelakh](https://community.stardog.com/u/Boris_Pelakh)\
**Post date:** [August 4, 2023, 1:26pm UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/1 "2023-08-04T13:26:39Z")

</div>

If I run SMS on a CSV, the order of bindings is pretty obvious - every row of the CSV is fed into the `WHERE` section, and the resulting bindings are then used to build the triples in the `TO` section. In this case, if do a `BIND(UUID() as ?row)` and then assert `?row a :Row`, I should expect one triple for each row in the CSV

However, If I have a nested JSON data structure with arrays of varying sizes, e.g.

```auto
{
  "elements": [
    {
      "eid": 1,
      "props": {
        "A": [
          {
            "pid": "1-A1"
          },
          {
            "pid": "1-A2"
          }
        ],
        "B": [
          {
            "pid": "1-B1"
          },
          {
            "pid": "1-B2"
          },
          {
            "pid": "1-B3"
          }
        ]
      }
    }
  ]
}

```

which I then map with

```auto
MAPPING :json_test
FROM JSON {
{
  "elements": [
    {
      "eid": "?eid",
      "props": {
        "A": [
          {
            "pid": "?prop_a_id"
          }
        ],
        "B": [
          {
            "pid": "?prop_b_id"
          }
        ]
      }
    }
  ]
}
}
TO {
   ?input_set :bindings ?bindings
}
WHERE {
    bind(uuid() as ?input_set)
	
    BIND(CONCAT(STR(?eid),'-',
      COALESCE(?prop_a_id, 'NO_A'),'-',
      COALESCE(?prop_b_id, 'NO_B')
	 ) as ?bindings)
}

```

would it result in a DFS traversal of the JSON structure with an input set emitted into the WHERE/TO at each leaf, i.e. I should expect 5 UUIDs bound with the inputs being

```auto
{eid:1,a_prop_id:"1-A1"}
{eid:1,a_prop_id:"1-A2"}
{eid:1,b_prop_id:"1-B1"}
{eid:1,b_prop_id:"1-B2"}
{eid:1,b_prop_id:"1-B3"}

```

because what I am seeing is quite different - I am seeing a single UUID bound to a cross product (6 values) of As and Bs. It gets even more interesting if not all values are populated - if the B array is empty, for example, I will get 2 bindings, one with each A value + '-NO\_B', but if the 'B' element is removed entirely, I get no bindings, even though A values are there. Is there a way to make a sub-tree as optional?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [September 11, 2023, 5:32pm UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/2 "2023-09-11T17:32:45Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [October 24, 2023, 5:51pm UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/3 "2023-10-24T17:51:16Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [December 11, 2023, 7:22pm UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/4 "2023-12-11T19:22:24Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [February 2, 2024, 2:50pm UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/5 "2024-02-02T14:50:43Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [March 30, 2024, 7:19pm UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/6 "2024-03-30T19:19:54Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [June 27, 2024, 10:43am UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/7 "2024-06-27T10:43:54Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [December 30, 2024, 8:16am UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/8 "2024-12-30T08:16:27Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [August 4, 2025, 11:09am UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/9 "2025-08-04T11:09:18Z")

</div>



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [March 28, 2026, 2:16pm UTC](https://community.stardog.com/t/unclear-interaction-of-sms2-from-json-with-arrays/4522/10 "2026-03-28T14:16:04Z")

</div>


