Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

readme with an example

  • Loading branch information...
commit c648480a16944580a25cf5e69c00436375e058b5 1 parent c1349fa
James Halliday authored
Showing with 94 additions and 0 deletions.
  1. +77 −0 README.markdown
  2. +10 −0 example/stub.js
  3. +7 −0 example/stub.json
77 README.markdown
View
@@ -0,0 +1,77 @@
+jsup
+====
+
+Update json strings in-place.
+
+example
+=======
+
+stub
+----
+
+stub.json:
+
+````javascript
+{
+ "a" : [ 1, 2, 333333, 4 ] ,
+ "b" : [ 3, 4, { "c" : [ 5, 6 ] } ],
+ "c" :
+ 444444,
+ "d" : null
+}
+````
+
+stub.js:
+
+````javascript
+var jsup = require('jsup');
+var fs = require('fs');
+var src = fs.readFileSync(__dirname + '/stub.json', 'utf8');
+
+var s = jsup(src)
+ .set([ 'a', 2 ], 3)
+ .set([ 'c' ], 'lul')
+ .stringify()
+;
+console.log(s);
+````
+
+output:
+
+ $ node stub.js
+ {
+ "a" : [ 1, 2, 3, 4 ] ,
+ "b" : [ 3, 4, { "c" : [ 5, 6 ] } ],
+ "c" :
+ "lul",
+ "d" : null
+ }
+
+methods
+=======
+
+var jsup = require('jsup');
+
+var j = jsup(src)
+-----------------
+
+Return a new jsup updater from the json string body `src`.
+
+j.get(path=[])
+--------------
+
+Get the element at `path`.
+
+j.set(path, value)
+------------------
+
+Replace the element at `path` with `value`, preserving indentation.
+
+Right now `value` will be run through `JSON.stringify()` for the replacement.
+
+There must be an element at `path` already or this method will throw.
+
+j.stringify()
+-------------
+
+Return the new string source with modifications, preserving indentation.
10 example/stub.js
View
@@ -0,0 +1,10 @@
+var jsup = require('jsup');
+var fs = require('fs');
+var src = fs.readFileSync(__dirname + '/stub.json', 'utf8');
+
+var s = jsup(src)
+ .set([ 'a', 2 ], 3)
+ .set([ 'c' ], 'lul')
+ .stringify()
+;
+console.log(s);
7 example/stub.json
View
@@ -0,0 +1,7 @@
+{
+ "a" : [ 1, 2, 333333, 4 ] ,
+ "b" : [ 3, 4, { "c" : [ 5, 6 ] } ],
+ "c" :
+ 444444,
+ "d" : null
+}
Please sign in to comment.
Something went wrong with that request. Please try again.