0

I am trying to generate an array like below using dataweave with two dynamic input i.e totalCount=1000 and splitNumber=100 in mule . I am able to do the same in Java script but not sure how to achieve this in dataweave.

{ start: 1, end: 100 },
{ start: 101, end: 200 },
{ start: 201, end: 300 },
{ start: 301, end: 400 },
{ start: 401, end: 500 },
{ start: 501, end: 600 },
{ start: 601, end: 700 },
{ start: 701, end: 800 },
{ start: 801, end: 900 },
{ start: 901, end: 1000 }
1
  • What exactly are you not able to get in dataweave? the sequence or this JSON format (which is actually an ndjson and not json array as you have mentioned) Commented Mar 18, 2024 at 6:26

1 Answer 1

1

You can try iterating (n - 1) times where n is totalCount/splitNumber i.e. 9 times

If you are expecting in json array format then try with changing output type to application/json

%dw 2.0
output application/x-ndjson
var totalCount=1000 
var splitNumber=100
---
0 to ((totalCount/splitNumber)-1) map(item,index)->{
        "start": (splitNumber * item) + 1,
        "end": (item + 1) * splitNumber
}



Sign up to request clarification or add additional context in comments.

Comments

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.