Skip to content

gmlewis/json-to-moonbit

Repository files navigation

gmlewis/json-to-moonbit

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.

Usage

  • 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

Status

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

Credits

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