# Help editing JSON files

**URL:** <https://discourse.cataclysmdda.org/t/help-editing-json-files/11799>\
**Category:** The Toolbox\
**Created:** [April 30, 2016, 10:39pm UTC](https://discourse.cataclysmdda.org/t/help-editing-json-files/11799 "2016-04-30T22:39:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alec\_White](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/alec_white/32/509_2.png) [@Alec\_White](https://discourse.cataclysmdda.org/u/Alec_White)\
**Post date:** [April 30, 2016, 10:39pm UTC](https://discourse.cataclysmdda.org/t/help-editing-json-files/11799/1 "2016-04-30T22:39:25Z")

</div>

Is there anyway or form to edit JSON trees/nodes, and apply complex modifications in bulk, like editing certain nodes that have certain values and so on?

---

<div class="post-metadata">

**Author:** ![pisskop](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/pisskop/32/1327_2.png) [@pisskop](https://discourse.cataclysmdda.org/u/pisskop)\
**Post date:** [April 30, 2016, 10:41pm UTC](https://discourse.cataclysmdda.org/t/help-editing-json-files/11799/2 "2016-04-30T22:41:05Z")

</div>

nodes?

You mean live cntrl+h and changing them all?

---

<div class="post-metadata">

**Author:** ![Alec\_White](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/alec_white/32/509_2.png) [@Alec\_White](https://discourse.cataclysmdda.org/u/Alec_White)\
**Post date:** [May 1, 2016, 12:02am UTC](https://discourse.cataclysmdda.org/t/help-editing-json-files/11799/3 "2016-05-01T00:02:06Z")

</div>

More on the lines of “copy every node that has X type and change it to Y, then add it after the copied node”.

I don’t know and can’t find a way to script it.

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [May 1, 2016, 1:20am UTC](https://discourse.cataclysmdda.org/t/help-editing-json-files/11799/4 "2016-05-01T01:20:08Z")

</div>

jq should be good for that.  
Alternatively python scripts.

---

<div class="post-metadata">

**Author:** ![Alec\_White](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/alec_white/32/509_2.png) [@Alec\_White](https://discourse.cataclysmdda.org/u/Alec_White)\
**Post date:** [May 1, 2016, 2:31am UTC](https://discourse.cataclysmdda.org/t/help-editing-json-files/11799/5 "2016-05-01T02:31:47Z")

</div>

[quote=“Coolthulhu, post:4, topic:11799”]jq should be good for that.  
Alternatively python scripts.[/quote]

By what is in the manual, doesn’t look like jq can copy/duplicate specific objects in an array.

So now I have to ask: How does the Python script system works? I mean, I don’t mind learning Python, but I don’t know what tools to use to run Python scripts over JSON files.

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [May 1, 2016, 3:02am UTC](https://discourse.cataclysmdda.org/t/help-editing-json-files/11799/6 "2016-05-01T03:02:47Z")

</div>

Python has a json library that operates on specific fields/entries. Basically, loads the jsons into a giant nested tree of arrays and dictionaries (in case of DDA, arrays of dictionaries).  
Not sure how does it handle formatting, though.

---

<div class="post-metadata">

**Author:** ![Alec\_White](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/alec_white/32/509_2.png) [@Alec\_White](https://discourse.cataclysmdda.org/u/Alec_White)\
**Post date:** [May 1, 2016, 4:23am UTC](https://discourse.cataclysmdda.org/t/help-editing-json-files/11799/7 "2016-05-01T04:23:55Z")

</div>

It looks that for formatting it would need to re-format after dumping.

[This](http://xahlee.info/perl-python/python_json_tutorial.html) is [more](https://docs.python.org/2/library/json.html) [FUN](http://chimera.labs.oreilly.com/books/1230000000393/ch06.html) than I thought. Anyway, I don’t know if sticking to the manual method or go cry-me-a-river to Stack Overflow.

It’ll be fun updating mods thou.
