Depending on how you’re delivering and formatting your data, there are cases where a variable is passed as a JSON string. DocuMerge does accept and will recognize JSON via webhook and our API integrations. However, and especially with HTTP Post Key/Value Pairs, one or more of your values may be a JSON string. When viewing your incoming data in DocuMerge, it might look something like this:
“product”: | “{“id”: 1, “name”: “Samsung Universe 9”, “price”: 1099, “stock”: 53}” |
Because this was delivered as a string, DocuMerge may not interpret this as a JSON object. To overcome this, use the “Field Map” tab of your Document or Route and apply the json_decode / json_encode Functions. Here’s the steps:
- Open the Field Map
Navigate to your document or route for the incoming data in question. Click on the “Field Map” tab.
- Find the Variable
Locate the variable(s) where your data is, or may be, passed as a string of JSON.
- Add the JSON Functions
In the text fields of each respective variable, add the json_decode/json_encode functions. Given our example above, we’d enter into the “product” field:
{$_product = json_decode($product, true)}{json_encode($_product)}
If our data may only at times contain a JSON string, we could add additional logic in attempt to detect a JSON string.{if $product|strstr:"{" and empty($product|strstr:"}")}{$_product = json_decode($product, true)}{json_encode($_product)}{/if}
- Save the Field Map
Make sure you click “Save Field Map” button to apply your changes.