Skip to content

Instantly share code, notes, and snippets.

@Hugoberry
Last active February 22, 2017 17:11
Show Gist options
  • Save Hugoberry/a9c9e8edec67ebce27840c604814eeff to your computer and use it in GitHub Desktop.
Save Hugoberry/a9c9e8edec67ebce27840c604814eeff to your computer and use it in GitHub Desktop.
JSON expansion in Power Query M
= List.Generate(
()=> [
can_expand=true,
level =1,
input =json,
output =[level.0=Record.FieldNames(json){0}]
],
each [can_expand],
each [
can_expand =Record.FieldValues([input]){0} is record,
level =[level]+1,
input =Record.FieldValues([input]){0},
output =[output]&( if Record.FieldValues(input){0} is record
then Record.AddField([],"level."&Number.ToText([level]),Record.FieldNames(input){0})
else input
)
],
each [output])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment