@gelight/json2sml

1.0.1 • Public • Published

@gelight/json2sml

Node package to convert JSON to SML

Dependencies

This library depends on SML (Simple Markup Language)

What is SML?

Guide - SML Specification

Video - SML in 60sec

Video - SML Explained

Using in Node.js

// Import the converter class from the module
import { Converter } from "@gelight/json2sml";

// JSON example
let json = {
    "firstName": "John",
    "lastName": "Smith",
    "age": 27,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": "10021-3100"
    }
}

// Use the converter to generate your SML document based on your JSON object
let doc = Converter.convert(json);

// Output > Logs all SML attributes from the SML element "address"
console.log(doc.getRoot().getElement("address").getAttributes());

Output:

[
  SmlAttribute {
    whitespaces: null,
    comment: null,
    name: 'streetAddress',
    values: [ '21 2nd Street' ]
  },
  SmlAttribute {
    whitespaces: null,
    comment: null,
    name: 'city',
    values: [ 'New York' ]
  },
  SmlAttribute {
    whitespaces: null,
    comment: null,
    name: 'state',
    values: [ 'NY' ]
  },
  SmlAttribute {
    whitespaces: null,
    comment: null,
    name: 'postalCode',
    values: [ '10021-3100' ]
  }
]

Using in browser

<html>
    <head>
        <title>JSON2SML - Node package to convert JSON to SML</title>
    </head>
    <body>
        <script src="https://unpkg.com/@gelight/json2sml"></script>
        <script>
          let json = {
              "firstName": "John",
              "lastName": "Smith",
              "age": 27,
              "address": {
                  "streetAddress": "21 2nd Street",
                  "city": "New York",
                  "state": "NY",
                  "postalCode": "10021-3100"
              }
          };
          
          let doc = JSON2SML.Converter.convert(json);
          
          console.log(doc.getRoot().getElement("address").getAttributes());
          
        </script>
    </body>
</html>

Package Sidebar

Install

npm i @gelight/json2sml

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

54.6 kB

Total Files

11

Last publish

Collaborators

  • gelight