1

I'm trying to convert json nested array's element and unable to get expected result, either I properly get name element or schemaExtensions element but can't get both together.

Here is my input:

{
  "rows": [
    {
      "content": {
        "name": {
          "content": "User"
        },
        "schemaExtensions": {
          "content": [
            {
              "content": {
                "schema": {
                  "content": "User"
                },
                "required": {
                  "content": true
                }
              }
            }
          ]
        }
      }
    }
  ]
}

And the JOlt spec definition:

  [
    {
      "operation": "shift",
      "spec": {
        "rows": {
          "*": {
            "content": {
              "name": {
                "content": "[&3].name"
              },
              "schemaExtensions": {
                "content": {
                  "*": {
                    "content": {
                      "schema": {
                        "content": "schemaExtensions.[&7].schema"
                      },
                      "required": {
                        "content": "schemaExtensions.[&7].required"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
]

The expected result:

[ {
  "name" : "User",
  "schemaExtensions": [ {
       "schema":"User",
       "required":true
    }]
}]

Here is the result I got when having both in my spec

[ {
  "name" : "User"
} ]

And if I remove name from my spec, then I get my schemaExtensions properly:

{
  "schemaExtensions" : [ {
    "schema" : "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
    "required" : true
  } ]
}

2 Answers 2

1

You can start with three level nesting to roam before writing the branches(name&schemaExtensions) explicitly. No need to write other key names such as

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "name": { "*": "&1" },
            "schemaExtensions": {
              "*": {
                "*": { "*": { "*": { "*": "&5.&1" } } }
              }
            }
          }
        }
      }
    }
  }
]
Sign up to request clarification or add additional context in comments.

2 Comments

No because I'll lose array from rows. Also name should be element from bigger elment in row not a row itself. But your answer gave me good hint for another one I have to produce
I've answered depending on the current case, if you have other elements than content within the leaf elements, then just replace "*": "&5.&1" with "content": "&5.&1" @ChristianDemers
0
 [
      {
        "operation": "shift",
        "spec": {
          "rows": {
            "*": {
              "content": {
                "name": {
                  "content": "[].name"
                },
                "schemaExtensions": {
                  "content": {
                    "*": {
                      "content": {
                        "schema": {
                          "content": "[&7].schemaExtensions[&7].schema"
                        },
                        "required": {
                          "content": "[&7].schemaExtensions[&7].required"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
        }
    ]

1 Comment

Thks, only thing I change, I kept [&3].name and everything work perfectly as expected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.