Bash + GNU utilities, 117 bytes
n=$[$1**$1] seq -f$1o%.fd$n+1-p $n|dc|rev|sed -r "s/(0+|$[$1-1]*).*$/\1/;s/^(0*)/\1$1/;s/^1/[1]/"|tr \\n0$[$1-1] \ [] The program essentially counts from 0 to (n^n)-1 in base n, where n is the input.
For each base-n number k in the count, it does the following:
- If k ends with at least one digit 0, print a '[' for each digit 0 at the end of k.
- Print n.
- If k ends with at least one digit n-1, print a ']' for each digit n-1 at the end of k.
(The value n=1 needs to have brackets added as a special case. This input value also generates some output to stderr, which can be ignored under standard PPCG rules.)
Maybe there's a shorter way to implement this idea.
Sample run:
./array 3 [[[3 3 3] [3 3 3] [3 3 3]] [[3 3 3] [3 3 3] [3 3 3]] [[3 3 3] [3 3 3] [3 3 3]]]