Package: jaiqu
JaiquReplicable, AI-generated JSON transformation queries. Transform any JSON into any schema automatically.Jaiqu is an AI agent for creating repeatable JSON transforms usingjq query languagesyntax. Jaiqu translates any arbitrary JSON inputs into any desired schema.Building AI agents? Check outAgentOpsFeaturesTranslate any schema to any schemaAI agent automatically maps data from a source schema to a desired format by iteratively prompting GPT-4 to create valid jq query syntax.Schema validationGiven a requirement schema, automatically validate whether the required data is present in the input json.Fuzzy term matchingInfers keys based on symantic similarity (i.e. datetime vs date_time). GPT-4 automaticlaly maps and translates input keys to desired output keys.Example usage:fromjaiquimportvalidate_schema,translate_schema# Desired data formatschema={"$schema":"http://json-schema.org/draft-07/schema#","type":"object","properties":{"id":{"type":["string","null"],"description":"A unique identifier for the record."},"date":{"type":"string","description":"A string describing the date."},"model":{"type":"string","description":"A text field representing the model used."}},"required":["id","date"]}# Provided datainput_json={"call.id":"123","datetime":"2022-01-01","timestamp":1640995200,"Address":"123 Main St","user":{"name":"John Doe","age":30,"contact":"john@email.com"}}# (Optional) Create hints so the agent knows what to look for in the inputkey_hints="We are processing outputs of an containing an id, a date, and a model. All the required fields should be present in this input, but the names might be different."Validating an input json contains all the information required in a schemaschema_properties,valid=validate_schema(input_json,schema,key_hints)print(schema_properties)>>>{"id":{"identified":true,"key":"call.id","message":"123","type":["string","null"],"description":"A unique identifier for the record.","required":true},"date":{"identified":true,"key":"datetime","message":"2022-01-01","type":"string","description":"A string describing the date.""required":true}}print(valid)>>>TrueCreating a repeatable jq query for extracitng data from identically formatted input JSONsjq_query=jaiqu.translate_schema(input_json,schema,key_hints,max_retries=30)>>>'{"id": .attributes["call.id"], "date": .datetime}'InstallationRecommended:PyPI:pipinstalljaiquArchitectureUnraveling the Jaiqu agentic workflow patternflowchart TD
    A[Start translate_schema] --> B{Validate input schema}
    B -- Valid --> C[For each key, create a jq filter query]
    B -- Invalid --> D[Throw RuntimeError]
    C --> E[Compile and Test jq Filter]
    E -- Success --> F[Validate JSON]
    E -- Fail --> G[Retry Create jq Filter]
    G -- Success --> E
    G -- Fail n times--> H[Throw RuntimeError]
    F -- Success --> I[Return jq query string]
    F -- Fail --> J[Retry Validate JSON]
    J -- Success --> I
    J -- Fail n times --> K[Throw RuntimeError]Running testsInstallpytestif you don't have it alreadypipinstallpytestRun thetests/folder while in the parent directorypytesttestsThis repo also supportstox, simply runpython -m tox.ContributingContributions to Jaiqu are welcome! Feel free to create anissuefor any bug reports, complaints, or feature suggestions.LicenseJaiqu is released under the MIT License.