Skip to content

Converting a multi nested JSON structure into a single array structure #267

Discussion options

You must be logged in to vote

Solved by changing my initial for to be [for (array(.networks))] and then did a flatten on the output. flatten(.products)

Final JSTL code

def test(node)
  if (is-array($node))
    [ {"Result": . }]
  else if (is-object($node))

       { "products":
        [for (array(.networks))
          let networkId = .id
          let description = .description
          let productTypes = array(.productTypes)
          if($productTypes)
            [for($productTypes)
              let productIdentity = .id
              let productCatType =.code
              let productCatTypeName = .description
              let fixedAmnt = .fixedAmount
              let products = array(.products)
              …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@AndrewDersley
Comment options

Answer selected by AndrewDersley
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
support Users asking how to solve a specific issue
2 participants