Advertisement
kamyar1979

Untitled

Apr 17th, 2018
2,598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.67 KB | None | 0 0
  1.  
  2. import std.conv : to;
  3. import std.utf : byChar;
  4. import std.file;
  5. import std.getopt;
  6. import std.json;
  7. import std.algorithm.iteration;
  8. import std.array;
  9.  
  10. void main(string[] args)
  11. {
  12.     string filename, path, value;
  13.  
  14.     auto helpInformation = getopt(args, "filename", &filename, "path", &path, "value", &value);
  15.  
  16.     scope (exit)
  17.     {
  18.         assert(exists(filename));
  19.         auto json = readText(filename);
  20.         auto parsed = parseJSON(json);
  21.         auto keys = path.split(".");
  22.         auto val = reduce!((a, b) => a[b])(parsed, keys[0..keys.length - 1]);
  23.         val[keys[keys.length - 1]] = value;
  24.         write(filename, toJSON(parsed, true));
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement