Skip to content
Browse all functions

Transform JSON format

data/json2json

json2json (Transform JSON format) is a 1001fx API function in the group Data & JSON: POST https://api.1001fx.com/data/json2json, 2 credits per call. It works as a ready-made module in Make and n8n or as a plain HTTP call.

2 credits per callHTTP APIn8nMake

Transform a JSON input to another JSON format using a template.

Try it in the 1001fx app

Run json2json in your browser with your API key – fill the form, click Run and get the answer or the file.

json2json in the 1001fx app: the form with example values
Transform JSON format in the 1001fx app

Endpoint

POSThttps://api.1001fx.com/data/json2json
Header
X-API-KEY: YOURSECRETAPIKEY How to
Content type
application/json

Parameters

  • templateJsonobjectoptional

    Template to be filled with data.

  • templateJsonStringstringoptional

    Stringified template to be filled with data. For expressions you can use the following syntaxes: {{ name }} and { { name } }.

    Example:
    {"creationDate":"{{info.created_at}}","creator":{"name":"{{info.created_by}}"},"people":["{{staff.developers}}",{"firstName":"{{name}}","city":"{{address.city}}","likes":"{{hobbies}}","hobbies":"=> join(hobbies,' & ')","age":"=> toNumber(age)","isAdmin":"=> toBoolean(isAdmin)"}]}
  • inputJsonobjectoptional

    JSON with data

  • inputJsonStringstringoptional

    Stringified JSON with data

    Example:
    {"info":{"created_at":"01.01.2023","created_by":"1001fx Admin"},"staff":{"developers":[{"name":"Rob","address":{"city":"London"},"hobbies":["cycling","hifi"],"age":"22","isAdmin":"true"},{"name":"Chris","address":{"city":"Oxford"},"hobbies":["hill walking"]}]}}

Examples

Template and input as JSON

Maps inputJson onto the shape of templateJson.

Input

Expects a json body
{
  "templateJson": {
    "creationDate": "{{info.created_at}}",
    "creator": {
      "name": "{{info.created_by}}"
    },
    "people": [
      "{{staff.developers}}",
      {
        "firstName": "{{name}}",
        "city": "{{address.city}}",
        "likes": "{{hobbies}}",
        "hobbies": "=> join(hobbies,' & ')",
        "age": "=> toNumber(age)",
        "isAdmin": "=> toBoolean(isAdmin)"
      }
    ]
  },
  "inputJson": {
    "info": {
      "created_at": "01.01.2023",
      "created_by": "1001fx Admin"
    },
    "staff": {
      "developers": [
        {
          "name": "Rob",
          "address": {
            "city": "London"
          },
          "hobbies": [
            "cycling",
            "hifi"
          ],
          "age": "22",
          "isAdmin": "true"
        },
        {
          "name": "Chris",
          "address": {
            "city": "Oxford"
          },
          "hobbies": [
            "hill walking"
          ]
        }
      ]
    }
  }
}

Output · HTTP 200

Response
{
  "result": {
    "creationDate": "01.01.2023",
    "creator": {
      "name": "1001fx Admin"
    },
    "people": [
      {
        "firstName": "Rob",
        "city": "London",
        "likes": [
          "cycling",
          "hifi"
        ],
        "hobbies": "cycling & hifi",
        "age": 22,
        "isAdmin": true
      },
      {
        "firstName": "Chris",
        "city": "Oxford",
        "likes": [
          "hill walking"
        ],
        "hobbies": "hill walking"
      }
    ]
  }
}
Show curl command
curl -X POST 'https://api.1001fx.com/data/json2json' \
  -H 'X-API-KEY: YOURSECRETAPIKEY' \
  -H 'Content-Type: application/json' \
  -d '{"templateJson":{"creationDate":"{{info.created_at}}","creator":{"name":"{{info.created_by}}"},"people":["{{staff.developers}}",{"firstName":"{{name}}","city":"{{address.city}}","likes":"{{hobbies}}","hobbies":"=> join(hobbies,'\'' & '\'')","age":"=> toNumber(age)","isAdmin":"=> toBoolean(isAdmin)"}]},"inputJson":{"info":{"created_at":"01.01.2023","created_by":"1001fx Admin"},"staff":{"developers":[{"name":"Rob","address":{"city":"London"},"hobbies":["cycling","hifi"],"age":"22","isAdmin":"true"},{"name":"Chris","address":{"city":"Oxford"},"hobbies":["hill walking"]}]}}}'

Template as JSON string

Same mapping, the template is passed as templateJsonString.

Input

Expects a json body
{
  "inputJson": {
    "info": {
      "created_at": "01.01.2023",
      "created_by": "1001fx Admin"
    },
    "staff": {
      "developers": [
        {
          "name": "Rob",
          "address": {
            "city": "London"
          },
          "hobbies": [
            "cycling",
            "hifi"
          ],
          "age": "22",
          "isAdmin": "true"
        },
        {
          "name": "Chris",
          "address": {
            "city": "Oxford"
          },
          "hobbies": [
            "hill walking"
          ]
        }
      ]
    }
  },
  "templateJsonString": "{\"creationDate\":\"{{info.created_at}}\",\"creator\":{\"name\":\"{{info.created_by}}\"},\"people\":[\"{{staff.developers}}\",{\"firstName\":\"{{name}}\",\"city\":\"{{address.city}}\",\"likes\":\"{{hobbies}}\",\"hobbies\":\"=> join(hobbies,' & ')\",\"age\":\"=> toNumber(age)\",\"isAdmin\":\"=> toBoolean(isAdmin)\"}]}"
}

Output · HTTP 200

Response
{
  "result": {
    "creationDate": "01.01.2023",
    "creator": {
      "name": "1001fx Admin"
    },
    "people": [
      {
        "firstName": "Rob",
        "city": "London",
        "likes": [
          "cycling",
          "hifi"
        ],
        "hobbies": "cycling & hifi",
        "age": 22,
        "isAdmin": true
      },
      {
        "firstName": "Chris",
        "city": "Oxford",
        "likes": [
          "hill walking"
        ],
        "hobbies": "hill walking"
      }
    ]
  }
}
Show curl command
curl -X POST 'https://api.1001fx.com/data/json2json' \
  -H 'X-API-KEY: YOURSECRETAPIKEY' \
  -H 'Content-Type: application/json' \
  -d '{"inputJson":{"info":{"created_at":"01.01.2023","created_by":"1001fx Admin"},"staff":{"developers":[{"name":"Rob","address":{"city":"London"},"hobbies":["cycling","hifi"],"age":"22","isAdmin":"true"},{"name":"Chris","address":{"city":"Oxford"},"hobbies":["hill walking"]}]}},"templateJsonString":"{\"creationDate\":\"{{info.created_at}}\",\"creator\":{\"name\":\"{{info.created_by}}\"},\"people\":[\"{{staff.developers}}\",{\"firstName\":\"{{name}}\",\"city\":\"{{address.city}}\",\"likes\":\"{{hobbies}}\",\"hobbies\":\"=> join(hobbies,'\'' & '\'')\",\"age\":\"=> toNumber(age)\",\"isAdmin\":\"=> toBoolean(isAdmin)\"}]}"}'

Input as JSON string

Same mapping, the input is passed as inputJsonString.

Input

Expects a json body
{
  "templateJson": {
    "creationDate": "{{info.created_at}}",
    "creator": {
      "name": "{{info.created_by}}"
    },
    "people": [
      "{{staff.developers}}",
      {
        "firstName": "{{name}}",
        "city": "{{address.city}}",
        "likes": "{{hobbies}}",
        "hobbies": "=> join(hobbies,' & ')",
        "age": "=> toNumber(age)",
        "isAdmin": "=> toBoolean(isAdmin)"
      }
    ]
  },
  "inputJsonString": "{\"info\":{\"created_at\":\"01.01.2023\",\"created_by\":\"1001fx Admin\"},\"staff\":{\"developers\":[{\"name\":\"Rob\",\"address\":{\"city\":\"London\"},\"hobbies\":[\"cycling\",\"hifi\"],\"age\":\"22\",\"isAdmin\":\"true\"},{\"name\":\"Chris\",\"address\":{\"city\":\"Oxford\"},\"hobbies\":[\"hill walking\"]}]}}"
}

Output · HTTP 200

Response
{
  "result": {
    "creationDate": "01.01.2023",
    "creator": {
      "name": "1001fx Admin"
    },
    "people": [
      {
        "firstName": "Rob",
        "city": "London",
        "likes": [
          "cycling",
          "hifi"
        ],
        "hobbies": "cycling & hifi",
        "age": 22,
        "isAdmin": true
      },
      {
        "firstName": "Chris",
        "city": "Oxford",
        "likes": [
          "hill walking"
        ],
        "hobbies": "hill walking"
      }
    ]
  }
}
Show curl command
curl -X POST 'https://api.1001fx.com/data/json2json' \
  -H 'X-API-KEY: YOURSECRETAPIKEY' \
  -H 'Content-Type: application/json' \
  -d '{"templateJson":{"creationDate":"{{info.created_at}}","creator":{"name":"{{info.created_by}}"},"people":["{{staff.developers}}",{"firstName":"{{name}}","city":"{{address.city}}","likes":"{{hobbies}}","hobbies":"=> join(hobbies,'\'' & '\'')","age":"=> toNumber(age)","isAdmin":"=> toBoolean(isAdmin)"}]},"inputJsonString":"{\"info\":{\"created_at\":\"01.01.2023\",\"created_by\":\"1001fx Admin\"},\"staff\":{\"developers\":[{\"name\":\"Rob\",\"address\":{\"city\":\"London\"},\"hobbies\":[\"cycling\",\"hifi\"],\"age\":\"22\",\"isAdmin\":\"true\"},{\"name\":\"Chris\",\"address\":{\"city\":\"Oxford\"},\"hobbies\":[\"hill walking\"]}]}}"}'

Try json2json now

Run it in your browser or create a free account and get 100 credits every month.

Changelog

  • 1.0.001.03.2023created
Ask 1001fx