Splitting similar array values to new output
See original GitHub issueHi, I have been looking for something similar and I don’t seem to be able to get my head around what I want. It’s easiest to explain it with my input and output:
input:
{
"name": "XXXXXX",
"url": "YYYYYY",
"healthReport": [
{
"description": "Test Result: 0 tests in total.",
"iconClassName": "icon-health-80plus",
"iconUrl": "health-80plus.png",
"score": 100
},
{
"description": "Test Result: 0 tests failing out of a total of 6 tests.",
"iconClassName": "icon-health-80plus",
"iconUrl": "health-80plus.png",
"score": 100
},
{
"description": "Build stability: No recent builds failed.",
"iconClassName": "icon-health-80plus",
"iconUrl": "health-80plus.png",
"score": 100
}
]
}
Desired output:
{
"name" : "XXXXXX",
"url" : "YYYYYY",
"testResults_desc" : "Test Result: 0 tests in total.",
"testResults_score" : 100,
"testResults2_desc" : "Test Result: 0 tests failing out of a total of 6 tests.",
"testResults2_score" : 100,
"buildStability_desc" : "Build stability: No recent builds failed.",
"buildStability_score" : 100
}
This is the spec I currently have:
[
{
"operation": "shift",
"spec": {
"name": "name",
"url": "url",
"healthReport": {
"*": {
"description": {
"Test Result*": {
"$": "testResults_desc",
"@(2,score)": "testResults_score"
},
"Build stability*": {
"$": "buildStability_desc",
"@(2,score)": "buildStability_score"
}
}
}
}
}
}
]
however, it is giving an output like this:
{
"name" : "XXXXXX",
"url" : "YYYYYY",
"testResults_desc" : [ "Test Result: 0 tests in total.", "Test Result: 0 tests failing out of a total of 6 tests." ],
"testResults_score" : [ 100, 100 ],
"buildStability_desc" : "Build stability: No recent builds failed.",
"buildStability_score" : 100
}
with the testResults being placed into an array. What I actually want is to split each ‘Test Result’ item into a separate column.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
JavaScript Split – How to Split a String into an Array in JS
You can split a string by each character using an empty string('') as the splitter. In the example below, we split the same...
Read more >How to split array by duplicate values? - Stack Overflow
You claim you need to split on duplicate values, but it looks like you're splitting on duplicate indices. Also, why bother using an...
Read more >Split an array into two equal Sum subarrays - GeeksforGeeks
A Simple solution is to run two loop to split array and check it is possible to split array into two parts such...
Read more >How do you split items inside an array?
Hi @Morke , The Split() function will return an array. We generally use Apply to each to traverse the elements in the array,...
Read more >NumPy Splitting Array - W3Schools
Splitting NumPy Arrays. Splitting is reverse operation of Joining. Joining merges multiple arrays into one and Splitting breaks one array into multiple.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Great thank you very much. I didn’t realise you could use indices as the keys. My only problem is, due to the input, each of these array elements can be in a random order so the solution would have to be dynamic.
I will work with what you have given and I appreciate the help thanks.
Thanks for answering. I ended up doing something very similar where I transform it three times. Your way is certainly cleaner though thanks.