
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Transforms loosely structured plain object strings into valid JSON strings
A utility that converts loosely structured data into valid JSON strings, ensuring data consistency and compatibility. It provides a safer alternative to using the Function
constructor to create objects from strings.
You can install this module using npm or yarn, it's only 2.93 kB │ gzip: 1.32 kB
:
npm i json-loose
# or
yarn add json-loose
Alternatively, you can also include this module directly in your HTML file from CDN:
Type | URL |
---|---|
ESM | https://cdn.jsdelivr.net/npm/json-loose/+esm |
CJS | https://cdn.jsdelivr.net/npm/json-loose/dist/index.cjs |
UMD | https://cdn.jsdelivr.net/npm/json-loose/dist/index.umd.js |
The jsonLoose
function takes an invalid JSON string as input and returns a JSON-like string representation of the transformed data.
import jsonLoose from 'json-loose'
const invalidJSON = `
{
name: 'Bambang Ekalaya',
username: "@palgunadi",
age: 30,
isStudent: true
}
`
const data = jsonLoose(invalidJSON)
// now you can `JSON.parse(data)`
console.log(data)
Yields:
{
"name": "Bambang Ekalaya",
"username": "@palgunadi",
"age": 30,
"isStudent": true
}
You can also specify an optional context object to transform Identifier values:
import jsonLoose from 'json-loose'
const invalidJSON = `
[
"foo",
true,
[1, 2, wife],
{
[n]: 'Bambang Ekalaya',
username: "@palgunadi",
age: 30,
address: [{city:city}, [country]],
skills: skills,
isStudent: true,
relation: {
wife: wife,
guru: guru,
[bar]: "qux"
},
},
],
`
const context = {
n: 'name',
skills: 'Archery',
city: 'Nishada',
country: 'Aravalli',
wife: 'Anggraini',
guru: 'Drona'
}
const data = jsonLoose(invalidJSON, context)
// now you can `JSON.parse(data)`
console.log(data)
Yields:
[
"foo",
true,
[1, 2, "Anggraini"],
{
"name": "Bambang Ekalaya",
"username": "@palgunadi",
"age": 30,
"address": [{ "city": "Nishada" }, ["Aravalli"]],
"skills": "Archery",
"isStudent": true,
"relation": { "wife": "Anggraini", "guru": "Drona", "bar": "qux" }
}
]
We 💛 issues.
When committing, please conform to the semantic-release commit standards. Please install commitizen
and the adapter globally, if you have not already.
npm i -g commitizen cz-conventional-changelog
Now you can use git cz
or just cz
instead of git commit
when committing. You can also use git-cz
, which is an alias for cz
.
git add . && git cz
A project by Stilearning © 2023.
FAQs
Transforms loosely structured plain object strings into valid JSON strings
The npm package json-loose receives a total of 3,408 weekly downloads. As such, json-loose popularity was classified as popular.
We found that json-loose demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.