Last active
March 23, 2024 10:48
-
-
Save PlugFox/e74d16fbf4508fb1366ef2b4d2eab6e6 to your computer and use it in GitHub Desktop.
Dart StackOverflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Dart StackOverflow | |
* https://gist.github.com/PlugFox/e74d16fbf4508fb1366ef2b4d2eab6e6 | |
* https://dartpad.dev?id=e74d16fbf4508fb1366ef2b4d2eab6e6 | |
* Mike Matiunin <plugfox@gmail.com>, 23 March 2024 | |
*/ | |
import 'dart:convert'; | |
const depth = 10000; | |
// dart compile exe bin/main.dart -o main | |
void main() { | |
final buffer = StringBuffer(); | |
for (var i = 0; i < depth; i++) { | |
buffer | |
..writeln('{') | |
..write(' ' * (i + 1)) | |
..write('"node": '); | |
} | |
buffer.writeln('"eof"'); | |
for (var i = depth; i > 0; i--) { | |
buffer | |
..write(' ' * (i - 1)) | |
..writeln('}'); | |
} | |
final json = buffer.toString(); | |
//print(json.replaceAll(RegExp(r'\s+'), ' ')); | |
final decoded = jsonDecode(json); | |
String? text; | |
try { | |
text = decoded.toString(); | |
} on Object catch (error, stackTrace) { | |
print('Error: $error\n$stackTrace'); | |
} | |
print(text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment