-1

I have 125k test cases and it takes 1 min and 30 secs before I could get the result. Is there any option to optimize my mapping? Thank you..

 const getEachValueByLine = () => {
    if (IsJsonString(multipleValue)) {
      setInvalidFormat(true)
      isValidRegex ? setValidRegex(true) : setValidRegex(false)
      const parseValue = Object.entries(JSON.parse(multipleValue))
      const addId = parseValue.map((item, index) => ({ id: index, case: item[0], expected: item[1] }))
      handleMultiValidate(addId)
    } else {
      setInvalidFormat(false)
    }
  }

The problem starts in here:

const parseValue = Object.entries(JSON.parse(multipleValue))
const addId = parseValue.map((item, index) => ({ id: index, case: item[0], expected: item[1] }))
1
  • This link will solve your problem. Use this Link Commented Jan 5, 2021 at 2:56

1 Answer 1

0

did you try big-json?

const fs = require('fs');
const path = require('path');
const json = require('big-json');
 
const readStream = fs.createReadStream('big.json');
const parseStream = json.createParseStream();
 
parseStream.on('data', function(pojo) {
    // => receive reconstructed POJO
});
 
readStream.pipe(parseStream);
Sign up to request clarification or add additional context in comments.

2 Comments

how to use this? do I just need to put the getEachValueByLine code to the receive reconstructed POJO?
parseStream.on(multipleValue, function(pojo) { // your code }); use like this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.