
Security News
The Next Open Source Security Race: Triage at Machine Speed
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.
json-amorph
Advanced tools
Convert JSON to AST, AST to JSON and transformation
const {json2ast, ast2json, transform} = require ('./index.js');
const json = {
hello1: 'hello world',
hello2: ['hello', 2, true],
hellonested: {
nested1: 'nested',
nested2: ['world', 7, false],
},
};
const ast = json2ast (json);
const json2 = ast2json (ast);
console.log ('JSON => AST => JSON');
console.log ('ORIGINAL: %O', json);
console.log ('AST: %O', ast);
console.log ('COPY: %O', json2);
console.log ('-------------------');
function pluginKeyReverse (api) {
return {
[api.AstType.key]: node => {
node.value.value = node.value.value.split ('').reverse ().join ('');
},
};
}
function pluginNotBoolean (api) {
return {
[api.AstType.boolean]: node => {
node.value = !node.value;
},
};
}
const result = transform (json, [pluginKeyReverse, pluginNotBoolean]);
console.log ('TRANSFORM:');
console.log ('ORIGINAL: %O', json);
console.log ('NEW JSON: %O', result.json);
console.log ('NEW AST: %O', result.ast);
console.log ('-------------------');
[gap@localhost amorph]$ npm run demo
> amorph@0.0.1 demo /home/gap/projects/amorph
> node ./example.js
JSON => AST => JSON
ORIGINAL: { hello1: 'hello world',
hello2: [ 'hello', 2, true ],
hellonested: { nested1: 'nested', nested2: [ 'world', 7, false ] } }
AST: { type: 'object',
value:
[ { type: 'pair', value: [Array] },
{ type: 'pair', value: [Array] },
{ type: 'pair', value: [Array] } ] }
COPY: { hello1: 'hello world',
hello2: [ 'hello', 2, true ],
hellonested: { nested1: 'nested', nested2: [ 'world', 7, false ] } }
-------------------
TRANSFORM:
ORIGINAL: { hello1: 'hello world',
hello2: [ 'hello', 2, true ],
hellonested: { nested1: 'nested', nested2: [ 'world', 7, false ] } }
NEW JSON: { '1olleh': 'hello world',
'2olleh': [ 'hello', 2, false ],
detsenolleh: { '1detsen': 'nested', '2detsen': [ 'world', 7, true ] } }
NEW AST: { type: 'object',
value:
[ { type: 'pair', value: [Array] },
{ type: 'pair', value: [Array] },
{ type: 'pair', value: [Array] } ] }
-------------------
Convert from some general user search request to Elasticsearch Query DSL format
From
{"prompt":"Hello world","offset":5,"limit":15,"language":"en"}
To
{"query":{"query_string":{"query":"Hello world"}},"from":5,"size":15,"type":"en_document"}
Source
const Amorph = require ('./index.js');
const UserSearchRequest = {
prompt: 'Hello world',
offset: 5,
limit: 15,
language: 'en',
};
function pluginPagination (api) {
return {
[api.AstType.key]: key => {
switch (api.getKeyName (key)) {
case 'offset':
key.value = api.createString ('from');
break;
case 'limit':
key.value = api.createString ('size');
break;
}
},
};
}
function pluginLanguage (api) {
return {
[api.AstType.pair]: pair => {
const kv = api.parsePair (pair);
if (kv.key === 'language') {
pair.value = [
api.createKey ('type'),
api.createValue (api.createString (kv.value + '_document')),
];
}
},
};
}
function pluginPrompt (api) {
return {
[api.AstType.pair]: pair => {
const kv = api.parsePair (pair);
if (kv.key === 'prompt') {
pair.value = [
api.createKey ('query'),
api.createValue (
api.createObject ([
api.createPair (
'query_string',
api.createObject ([
api.createPair ('query', api.createString (kv.value)),
])
),
])
),
];
}
},
};
}
const ElasticSearchRequest = Amorph.transform (UserSearchRequest, [
pluginPagination,
pluginLanguage,
pluginPrompt,
]);
console.log ();
console.log (JSON.stringify (UserSearchRequest));
console.log ();
console.log (JSON.stringify (ElasticSearchRequest.json));
console.log ();
FAQs
transform json
The npm package json-amorph receives a total of 1 weekly downloads. As such, json-amorph popularity was classified as not popular.
We found that json-amorph demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.

Security News
gem.coop is testing registry-level dependency cooldowns to limit exposure during the brief window when malicious gems are most likely to spread.