You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@gelight/json2sml

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gelight/json2sml

Node package to convert JSON to SML

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

@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>

Keywords

ReliableTxt

FAQs

Package last updated on 22 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts