Parse JSON captured via email to obtain data

  • 763 Views
  • Last Post 06 March 2024
Ricardo Mejia posted this 16 December 2023

Hi! I am trying to develop a new workflow, using the scripting capabilities of Sharescan. I was able to capture JSON files sent to an email address, but I need to "read" the data of several properties of the JSON in order to store them in a database. All the JSON files will have the same structure, like below.

I need to capture the properties "numeroControl" and "codigoGeneracion". Any help will be appreciated.

best regards.

 

  "identificacion": {

    "version": 1,

    "ambiente": "01",

    "tipoDte": "01",

    "numeroControl": "DTE-01-0000375-000000000000032",

    "codigoGeneracion": "3GGG9B-3aB5-4d83-B591-311BCF7FFFB4",

    "tipoModelo": 1,

    "tipoOperacion": 1,

    "tipoContingencia": null,

    "motivoContin": null,

    "fecEmi": "2025-10-11",

    "horEmi": "18:56:12",

    "tipoMoneda": "USD"

  }

Order By: Standard | Newest | Votes
luca.scarpati posted this 21 December 2023

Hi Ricardo,

 

we hope you refer to Scanshare and not the other tongue-out.

How did you manage to capture it? I believe you put it in a variable in text/string form, so you need to parse it maybe with some regExp in VBS or JS as if it were a normal piece of text recovered from a document.

The RegExp that you can use should be something like this:

  • refer to numeroControl: ([A-Z]{3}[ -]*[0-9]{2}[ -]*[0-9]+[ -]*[0-9]+)
  • refer to codigoGeneracion: ([A-Z0-9]{6}[ -]*[0-9A-z]{4}[ -]*[0-9A-z]{4}[ -]*[0-9A-z]{4}[ -]*[0-9A-z]{12})

For more examples you can check the forum category "Samples & Materials" and if you need some other extra specific info please contact the support.

 

Have a nice day!

 

Best regards,

Luca

olgabotezatu posted this 06 March 2024

To extract the properties "numeroControl" and "codigoGeneracion" from the JSON files after customer data enrichment, you can use a scripting language like Python. Below is a Python script that demonstrates how to read the JSON data from a file and extract the desired properties:

import json

# Function to extract properties from JSON
def extract_properties(json_data):
    try:
        # Load JSON data
        data = json.loads(json_data)
        
        # Extract properties
        numero_control = data["identificacion"]["numeroControl"]
        codigo_generacion = data["identificacion"]["codigoGeneracion"]
        
        return numero_control, codigo_generacion
    except KeyError:
        # Handle missing keys
        print("One or more required keys not found in JSON data.")
        return None, None
    except json.JSONDecodeError:
        # Handle invalid JSON format
        print("Invalid JSON format.")
        return None, None

# Example usage
json_data = '''
{
  "identificacion": {
    "version": 1,
    "ambiente": "01",
    "tipoDte": "01",
    "numeroControl": "DTE-01-0000375-000000000000032",
    "codigoGeneracion": "3GGG9B-3aB5-4d83-B591-311BCF7FFFB4",
    "tipoModelo": 1,
    "tipoOperacion": 1,
    "tipoContingencia": null,
    "motivoContin": null,
    "fecEmi": "2025-10-11",
    "horEmi": "18:56:12",
    "tipoMoneda": "USD"
  }
}
'''

numero_control, codigo_generacion = extract_properties(json_data)
if numero_control is not None and codigo_generacion is not None:
    print("Numero Control:", numero_control)
    print("Codigo Generacion:", codigo_generacion)

You can save this script into a Python file (e.g., extract_properties.py) and run it on each JSON file you receive from Scanshare. This script will extract the "numeroControl" and "codigoGeneracion" properties from the JSON data and print them out. You can then modify the script to store these values in a database as per your requirements.

Close