@gelight/json2sml
v1.0.1
Published
Node package to convert JSON to SML
Downloads
9
Maintainers
Readme
@gelight/json2sml
Node package to convert JSON to SML
Dependencies
This library depends on SML (Simple Markup Language)
What is SML?
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>