Recommend an AI model for structured (json)


I’m very new to AI, but a long-term JS engineer.

I want to find a model to do the following (currently I use ChatGPT which does this well):

Can you find all the date, and heading fields from this JSON Object: {...complex json object}. The output should be [{date:'',heading:''}....]

In my basic understanding, the model needs to be good at two things: Natural language processing (mainly english) and reading structured data.

Is there a model you can suggest using for this?


The most recommended AI model for working with structured data of json is transformers library by hugging face.

Yes, I can help you with that. For your requirements of natural language processing and reading structured data, a suitable model to consider is BERT (Bidirectional Encoder Representations from Transformers). BERT is a transformer-based model that has been pre-trained on a large corpus of text and has achieved state-of-the-art results on various natural language processing tasks.

To extract the date and heading fields from your JSON object, you can follow these steps:

  1. Convert the JSON object to text format.
  2. Preprocess the text by tokenizing it into a format suitable for BERT input.
  3. Use BERT to process the preprocessed text and obtain contextualized representations for each token.
  4. Apply a suitable technique to identify the date and heading fields based on the contextualized representations.
  5. Retrieve the identified date and heading fields from the original JSON object.

Here’s a basic example in JavaScript using the transformers library to demonstrate the usage of BERT for your task:


const { pipeline } = require('ts-migrate');
const { Tokenizer, BasicTokenizer } = require('ts-migrate');

async function extractDateAndHeading(jsonObj) {
  // Convert the JSON object to text format
  const text = JSON.stringify(jsonObj);

  // Preprocess the text using the BERT tokenizer
  const tokenizer = await Tokenizer.fromPretrained('bert-base-uncased');
  const tokens = tokenizer.tokenize(text);

  // Process the tokens with BERT to obtain contextualized representations
  const model = await pipeline('bert-base-uncased');
  const representations = await model(tokens);

  // Identify the date and heading fields based on the contextualized representations
  const dates = [];
  const headings = [];
  for (let i = 0; i < tokens.length; i++) {
    const token = tokens[i];
    const representation = representations[i];

    // Add your logic here to identify dates and headings based on the representations

    if (isDate(representation)) {

    if (isHeading(representation)) {

  // Retrieve the identified date and heading fields from the original JSON object
  const extractedData = [];
  dates.forEach((dateToken) => {
    const dateValue = jsonObj[dateToken];
    headings.forEach((headingToken) => {
      const headingValue = jsonObj[headingToken];
      extractedData.push({ date: dateValue, heading: headingValue });

  return extractedData;

// Example usage
const jsonObject = { ...complex json object };
const extractedFields = await extractDateAndHeading(jsonObject);

Please note that the above example provides a basic structure and you would need to adapt it to your specific requirements. You may also need to define your own logic for identifying the date and heading fields based on the contextualized representations.