Translates JSON into MoonBit code. Check it out!
This is based on Matt Holt's json-to-go.
Things to note:
- The script sometimes has to make some assumptions, so give the output a once-over.
- In an array of objects, it is assumed that the first object is representative of the rest of them.
- The output is indented, but not formatted. Use
moon fmt
!
Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.
-
Read JSON file:
node json-to-moonbit.js sample.json # or bun json-to-moonbit.js sample.json
-
Read JSON file from stdin:
node json-to-moonbit.js < sample.json cat sample.json | node json-to-moonbit.js # or bun json-to-moonbit.js < sample.json cat sample.json | bun json-to-moonbit.js
The code has been updated to support compiler:
$ moon version --all
moon 0.1.20240920 (13f54ef 2024-09-20) ~/.moon/bin/moon
moonc v0.1.20240920+a1bf2bf0d ~/.moon/bin/moonc
moonrun 0.1.20240920 (13f54ef 2024-09-20) ~/.moon/bin/moonrun
JSON-to-Go is brought to you by Matt Holt (mholt6).
JSON-to-MoonBit is brought to you by Glenn Lewis.
diff is Copyright (c) 2009-2015, Kevin Decker kpdecker@gmail.com All rights reserved. and is used for testing. It is from: https://github.com/kpdecker/jsdiff/ with license: https://github.com/kpdecker/jsdiff/blob/master/LICENSE