|
| 1 | + |
| 2 | +# demo jsonjoin |
| 3 | + |
| 4 | +Consider two JSON objects one in person.json and another |
| 5 | +in profile.json. |
| 6 | + |
| 7 | +person.json contains |
| 8 | + |
| 9 | +```shell |
| 10 | + { "name": "Doe, Jane", "email": "[email protected]", "age": 42 } |
| 11 | +``` |
| 12 | +
|
| 13 | +profile.json contains |
| 14 | +
|
| 15 | +```json |
| 16 | + { "name": "Doe, Jane", "bio": "World renowned geophysist.", |
| 17 | + |
| 18 | +``` |
| 19 | +
|
| 20 | +A simple join of person.json with profile.json (note the |
| 21 | +-create option) |
| 22 | +
|
| 23 | +```shell |
| 24 | + jsonjoin -create person.json profile.json |
| 25 | +``` |
| 26 | +
|
| 27 | +would yield and object like |
| 28 | +
|
| 29 | +```json |
| 30 | + { |
| 31 | + "person": { "name": "Doe, Jane", "email": "[email protected]", |
| 32 | + "age": 42}, |
| 33 | + "profile": { "name": "Doe, Jane", "bio": "World renowned geophysist.", |
| 34 | + |
| 35 | + } |
| 36 | +``` |
| 37 | +
|
| 38 | +Likewise if you want to treat person.json as the root object and add |
| 39 | +profile.json as a branch try |
| 40 | +
|
| 41 | +```shell |
| 42 | + cat person.json | jsonjoin profile.json |
| 43 | +``` |
| 44 | +
|
| 45 | +or |
| 46 | +
|
| 47 | +```shell |
| 48 | + jsonjoin -i person.json profile.json |
| 49 | +``` |
| 50 | +
|
| 51 | +this yields an object like |
| 52 | +
|
| 53 | +```json |
| 54 | + { |
| 55 | + "name": "Doe, Jane", "email":"[email protected]", "age": 42, |
| 56 | + "profile": { "name": "Doe, Jane", "bio": "World renowned geophysist.", |
| 57 | + |
| 58 | + } |
| 59 | +``` |
| 60 | +
|
| 61 | +You can modify this behavor with -update or -overwrite. Both options are |
| 62 | +order dependant (i.e. not associative, A update B does |
| 63 | +not necessarily equal B update A). |
| 64 | +
|
| 65 | ++ -update will add unique key/values from the second object to the first object |
| 66 | ++ -overwrite replace key/values in first object one with second objects' |
| 67 | +
|
| 68 | +Running |
| 69 | +
|
| 70 | +```shell |
| 71 | + jsonjoin -create -update person.json profile.json |
| 72 | +``` |
| 73 | +
|
| 74 | +would yield |
| 75 | +
|
| 76 | +```json |
| 77 | + { "name": "Doe, Jane", "email":"[email protected]", "age": 42, |
| 78 | + "bio": "World renowned geophysist." } |
| 79 | +``` |
| 80 | +
|
| 81 | +Running |
| 82 | +
|
| 83 | +```shell |
| 84 | + jsonjoin -create -update profile.json person.json |
| 85 | +``` |
| 86 | +
|
| 87 | +would yield |
| 88 | +
|
| 89 | +```json |
| 90 | + { "name": "Doe, Jane", "age": 42, |
| 91 | + "bio": "World renowned geophysist.", |
| 92 | + |
| 93 | +``` |
| 94 | +
|
| 95 | +Running |
| 96 | +
|
| 97 | +```shell |
| 98 | + jsonjoin -create -overwrite person.json profile.json |
| 99 | +``` |
| 100 | +
|
| 101 | +would yield |
| 102 | +
|
| 103 | +```json |
| 104 | + { "name": "Doe, Jane", "email":"[email protected]", "age": 42, |
| 105 | + "bio": "World renowned geophysist." } |
| 106 | +``` |
| 107 | +
|
0 commit comments