question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Splitting similar array values to new output

See original GitHub issue

Hi, 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:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Xpipecommented, Oct 11, 2018

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.

0reactions
Xpipecommented, Oct 25, 2018

Thanks for answering. I ended up doing something very similar where I transform it three times. Your way is certainly cleaner though thanks.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found