Mixed array and object JSON

Hello, I have a feed coming from github which I need to get certain attributes but some of the items are being returned as arrays and some are being returned as objects!

Does anyone know how I can align the 2 types together to perform downstream tasks?

[
	[{
		"name": "stale.yml",
		"path": ".github/workflows/stale.yml",
		"sha": "xx",
		"size": 425,
		"url": "https://api.github.com/owners/Owner/repo/contents/.github/workflows/stale.yml?ref=BTRANCH",
		"html_url": "https://github.com/Owner/repo/blob/BTRANCH/.github/workflows/stale.yml",
		"git_url": "https://api.github.com/owners/Owner/repo/git/blobs/1234",
		"download_url": "https://raw.githubusercontent.com/Owner/repo/BTRANCH/.github/workflows/stale.yml?token=xx",
		"type": "file",
		"_links": {
			"self": "https://api.github.com/owners/Owner/repo/contents/.github/workflows/stale.yml?ref=BTRANCH",
			"git": "https://api.github.com/owners/Owner/repo/git/blobs/1234",
			"html": "https://github.com/Owner/repo/blob/BTRANCH/.github/workflows/stale.yml"
		}
	}],
	{
		"name": "pipeline",
		"path": "BLAH/pipeline",
		"sha": "1234",
		"size": 40246,
		"url": "https://api.github.com/owners/Owner/repo/contents/BLAH/pipeline?ref=BTRANCH",
		"html_url": "https://github.com/Owner/repo/blob/BTRANCH/BLAH/pipeline",
		"git_url": "https://api.github.com/owners/Owner/repo/git/blobs/1234",
		"download_url": "https://raw.githubusercontent.com/Owner/repo/BTRANCH/BLAH/pipeline?token=xx",
		"type": "file",
		"content": "xx"
		"encoding": "base64",
		"_links": {
			"self": "https://api.github.com/owners/Owner/repo/contents/BLAH/pipeline?ref=BTRANCH",
			"git": "https://api.github.com/owners/Owner/repo/git/blobs/1234",
			"html": "https://github.com/Owner/repo/blob/BTRANCH/BLAH/pipeline"
		}
	}
]
1 Like

Common problem - you can make sure that they will all be arrays by using the built-in function

sl.ensureArray()
1 Like

I just get an error from using that

Try it this way:

1 Like

wow, it was that easy!

I tried every other combination except for that one!

Thanks for your help

2 Likes