npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-to-java

v1.4.7

Published

node module converting formatted json into java files

Downloads

10

Readme

json-to-java

Table of content

how to use in shell

$ json-to-java -s path/to/src.json -o path/to/output.java

json-to-java accepts arguments:

  • --src (-s)
    • path to source json file
    • default to input.json
  • --output (-o) path to output java file
    • default to %arguemnt::src%.java, e.g. input.json.java

how to use as node module

New an Java notation instance, and get generated java via instance.toString()

You may need to configure ConvertOptions

scheme of source json

Sample file see in directory sample-input-json

Should be a JsonObject

  • fileDescription
    • comments at the top of the file
    • optional, default to null
    • Accept type: null, string, string[], JsonObject(Dictionary<string>)
  • convertOptions
  • package
    • optional, default to empty string (would not be convert)
    • Accept type: string
  • imports
    • optional, default to empty array
    • Accept type: string[]
  • entry
  • entryType
    • optional, default to "class"
    • Accept values: "class"

ConvertOptions

Should be a JsonObject

  • indent
    • optional, default to indent size 4
    • Accept value: a number or "tab"

JavaClass

Should be a JsonObject

  • annotations
  • accessModifier
    • optional, default to null
    • Accept values: null or "public" or "private" or "protected"
  • nonAccessModifiers
    • optional, default to empty array
    • Accept values: string[]
      • repeated value will not be checked (TODO: add check to this)
      • each element should be one of: "static" or "final" or "abstract" or "transient" or "synchronized" or "volatile"
  • name
    • required
    • Accept type: string
      • validtor: /^[a-zA-Z_][a-zA-Z0-9_]*$/
  • extends
    • optional, only become effective when a value is set
    • Accept type: string
  • implements
    • optional, default to empty array
    • Accept types
      • string would be read as an single-value array
      • string[]
  • attributes
  • constructors
  • methods
  • classes
    • optional, default to empty array
    • Accept type: JavaClass[]

JavaAnnotation

Should be a JsonObject

  • name
    • required
    • Accept type: string
      • validtor: /^[a-zA-Z_][a-zA-Z0-9_]*$/
  • values
    • optional, default to null
    • Accept value/types
      • null: no values, as MarkerAnnotation
      • string: represent to a single value, as SingleValueAnnotation
      • Dictionary<string>: represent to key-value pairs, as FullAnnotation

JavaClassAttributes

Should be a JsonObject

  • accessModifier
    • optional, default to null
    • Accept values: null or "public" or "private" or "protected"
  • nonAccessModifiers
    • optional, default to empty array
    • Accept values: string[]
      • repeated value will not be checked (TODO: add check to this)
      • each element should be one of: "static" or "final" or "abstract" or "transient" or "synchronized" or "volatile"
  • type
    • required
    • Accept type: string
  • name
    • required
    • Accept type: string
      • validtor: /^[a-zA-Z_][a-zA-Z0-9_]*$/
  • value
    • optional, default to null
    • Accept value/type
      • null: this attribute would have no initial value
      • string: string like "0" or "\"String value\""

JavaClassConstructor

Should be a JsonObject

  • accessModifier
    • optional, default to null
    • Accept values: null or "public" or "private" or "protected"
  • name
    • required
    • Accept type: string
      • validtor: /^[a-zA-Z_][a-zA-Z0-9_]*$/
  • arguments
  • statements

JavaClassMethod

Should be a JsonObject

  • annotations
  • accessModifier
    • optional, default to null
    • Accept values: null or "public" or "private" or "protected"
  • nonAccessModifiers
    • optional, default to empty array
    • Accept values: string[]
      • repeated value will not be checked (TODO: add check to this)
      • each element should be one of: "static" or "final" or "abstract" or "transient" or "synchronized" or "volatile"
  • type
    • required
    • Accept type: string
  • name
    • required
    • Accept type: string
      • validtor: /^[a-zA-Z_][a-zA-Z0-9_]*$/
  • arguments
  • statements

JavaVariableDifinition

Should be a JsonObject

  • final
    • optional, default to false
    • Accept type: boolean (true or false)
  • type
    • required
    • Accept type: string

JavaStatement

A JavaStatement can be:

  • string as a statement line
  • JavaStatement[] as a nested code block, indentation would be increased automatically

Sample:

const statements: JavaStatement[] = [
  "if (true) {",
  [
    "while (false) {",
    [ "// unreachable" ],
    "}"
  ],
  "} else {",
  [ "throw new RuntimeException();" ],
  "}"
]

would be converted into:

if (true) {
  while (false) {
    // unreachable
  }
} else {
  throw new RuntimeException();
}