Skip to content

replicadse/fmerge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fmerge

fmerge is a tool that allows merging files recursively and with custom placeholder patterns. The include file statements are always relative to the file that includes them.

Example

Test data

root.json

{
    "data": [
        {{ ./item1.json }},
        {{ ./item2.json }}
    ]
}

item1.json

{
    "name": "Item 1",
    "data": {{ ./item_data.json }}
}

item2.json

{
    "name": "Item 2",
    "data": {{ ./item_data.json }}
}

item_data.json

{
    "foo": "bar"
}

Execution

Merging these files together can be done by executing the following code:

fmerge merge -f=./root.json -p="{{ %f }}"

The resulting file will be printed to STDOUT and will look like this:

{
    "data": [
        {
    "name": "Item 1",
    "data": {
    "foo": "bar"
}
},
        {
    "name": "Item 2",
    "data": {
    "foo": "bar"
}
}
    ]
}

The text replacement is done without respect to the formatting. The structure above is valid JSON, just formatted incorrectly. fmerge does not modify the content it merges in any way, shape or form.
The correctly formatted JSON looks as follows:

{
  "data": [
    {
      "name": "Item 1",
      "data": {
        "foo": "bar"
      }
    },
    {
      "name": "Item 2",
      "data": {
        "foo": "bar"
      }
    }
  ]
}