Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9c41786

Browse files
author
andrew85
committed
first commit
0 parents commit 9c41786

16 files changed

+9410
-0
lines changed

‎.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
target
3+
!/node_modules/
4+
/node_modules/
5+
.idea/inspectionProfiles/
6+
/.idea
7+
/.npmignore
8+
/public/root_domain_process.html

‎LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Andrew-Kang-G
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# json-knife [![NPM version](https://img.shields.io/npm/v/json-knife.svg)](https://www.npmjs.com/package/json-knife) [![](https://data.jsdelivr.com/v1/package/gh/Andrew-Kang-G/json-knife/badge)](https://www.jsdelivr.com/package/gh/Andrew-Kang-G/json-knife)
2+
## Overview
3+
Mass Update certain key-values recursively in huge, complex JSON string trees
4+
without using JSON.parse() & self-calling function.
5+
6+
Zero dependency, 7KB
7+
8+
## Installation
9+
10+
For ES5 users,
11+
12+
``` html
13+
<html>
14+
<body>
15+
<script src="../dist/json-knife.bundle.js"></script>
16+
<script type="text/javascript">
17+
18+
</script>
19+
</body>
20+
</html>
21+
```
22+
23+
For ES6 npm users, do 'npm install --save json-knife' on console.
24+
25+
``` html
26+
import Pattern from 'json-knife';
27+
```
28+
29+
## Syntax & Usage
30+
Very simple to use. Now we are going to set all 'Mike{[Gentleman]}' to null in the sample JSON string.
31+
32+
```javascript
33+
34+
/**
35+
* @brief
36+
* Mass Update certain key-values recursively in huge, complex JSON string trees
37+
* @author Andrew Kang
38+
* @param original string required (must be JSON string)
39+
* @param key string required
40+
* @param value string or boolean or number or null required
41+
* @return string
42+
*/
43+
44+
// IMPORTANT : the variable 'original' should be valid JSON.
45+
// You can test your JSON string source like here.
46+
// https://jsonformatter.curiousconcept.com/
47+
48+
var result = Pattern.sculptJson(original, 'Mike{[Gentleman]}', null);
49+
50+
// You can convert the result string to an object type.
51+
var resultObj = JSON.parse(result);
52+
53+
```
54+
**[Original source]**
55+
56+
var original =
57+
```json
58+
{
59+
"prob\"lems": [{
60+
"classes": [{
61+
"medications": [{
62+
"medicationsClasses": [{
63+
"Mike {[Gentleman]}": [{
64+
"associatedDrug": [{
65+
"name": "asprin",
66+
"dose": 35.3,
67+
"strength": "500 mg",
68+
"className" : false
69+
}],
70+
"Mike {[Gentleman]}": [{
71+
"name": "somethingElse",
72+
"dose": "",
73+
"strength": "500 mg",
74+
"friends": {
75+
"self": {
76+
"Mike {[Gentleman]}": "33",
77+
"names": ["aa"]
78+
}
79+
}
80+
}]
81+
}],
82+
"Judy": [{
83+
"associatedDrug": [{
84+
"name": "asprin",
85+
"dose": "",
86+
"strength": "500 mg",
87+
"friends": ["Mike {[Gentleman]}"]
88+
}],
89+
"associatedDrug#2": [{
90+
"name": "somethingElse",
91+
"dose": "",
92+
"strength": "500 mg"
93+
}],
94+
"friends": [{"Mike {[Gentleman]}": null}, {"Mike {[Gentleman]}": [["c[ 3\"5ool", 35], ["ca],[1\"3lm"], 53]}, "Jackson", "Mike {[Gentleman]}"]
95+
}]
96+
}]
97+
}],
98+
"classNameMissed": [{
99+
"Mike {[Gentleman]}": "missing_value"
100+
}]
101+
}],
102+
"className": [{}]
103+
}]
104+
}
105+
```
106+
**[Result]** - string type
107+
108+
```json
109+
{
110+
"prob\"lems": [{
111+
"classes": [{
112+
"medications": [{
113+
"medicationsClasses": [{
114+
"Mike {[Gentleman]}": null,
115+
"Judy": [{
116+
"associatedDrug": [{
117+
"name": "asprin",
118+
"dose": "",
119+
"strength": "500 mg",
120+
"friends": ["Mike {[Gentleman]}"]
121+
}],
122+
"associatedDrug#2": [{
123+
"name": "somethingElse",
124+
"dose": "",
125+
"strength": "500 mg"
126+
}],
127+
"friends": [{"Mike {[Gentleman]}": null}, {"Mike {[Gentleman]}": null}, "Jackson", "Mike {[Gentleman]}"]
128+
}]
129+
}]
130+
}],
131+
"classNameMissed": [{
132+
"Mike {[Gentleman]}": null
133+
}]
134+
}],
135+
"className": [{}]
136+
}]
137+
}
138+
```
139+
140+
Please inform me of the source related things by leaving issues on Github or emailing me at studypurpose@naver.com.

‎dist/json-knife.bundle.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gulpfile.babel.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import gulp from 'gulp';
2+
import babel from 'gulp-babel';
3+
import mocha from 'gulp-mocha';
4+
import gutil from 'gulp-util';
5+
import webpack from 'webpack';
6+
import webpackConfig from './webpack.config.babel';
7+
import WebpackDevServer from 'webpack-dev-server';
8+
9+
gulp.task('default', ['webpack']);
10+
11+
gulp.task('babel', () => {
12+
return gulp.src('src/*.js')
13+
.pipe(babel())
14+
.pipe(gulp.dest('target'));
15+
});
16+
17+
gulp.task('test', ['babel'], () => {
18+
return gulp.src('test/*.js')
19+
.pipe(mocha())
20+
.on('error', () => {
21+
gulp.emit('end');
22+
});
23+
});
24+
25+
gulp.task('watch-test', () => {
26+
return gulp.watch(['src/**', 'test/**'], ['test']);
27+
});
28+
29+
gulp.task('webpack', ['test'], function(callback) {
30+
var myConfig = Object.create(webpackConfig);
31+
myConfig.plugins = [
32+
new webpack.optimize.DedupePlugin(),
33+
new webpack.optimize.UglifyJsPlugin()
34+
];
35+
36+
// run webpack
37+
webpack(myConfig, function(err, stats) {
38+
if (err) throw new gutil.PluginError('webpack', err);
39+
gutil.log('[webpack]', stats.toString({
40+
colors: true,
41+
progress: true
42+
}));
43+
callback();
44+
});
45+
});
46+
47+
gulp.task('server', ['webpack'], function(callback) {
48+
// modify some webpack config options
49+
var myConfig = Object.create(webpackConfig);
50+
myConfig.devtool = 'eval';
51+
myConfig.debug = true;
52+
53+
// Start a webpack-dev-server
54+
new WebpackDevServer(webpack(myConfig), {
55+
publicPath: '/' + myConfig.output.publicPath,
56+
stats: {
57+
colors: true
58+
},
59+
hot: true
60+
}).listen(8080, 'localhost', function(err) {
61+
if(err) throw new gutil.PluginError('webpack-dev-server', err);
62+
gutil.log('[webpack-dev-server]', 'http://localhost:8080/webpack-dev-server/index.html');
63+
});
64+
});

‎license.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
json-knife
2+
https://github.com/Andrew-Kang-G/json-knife
3+
4+
The MIT License (MIT)
5+
6+
Copyright (c) 2019 Andrew-Kang-G
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in all
16+
copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
SOFTWARE.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /