Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for JSON values #50

Open
Laykou opened this issue Sep 7, 2023 · 2 comments
Open

Support for JSON values #50

Laykou opened this issue Sep 7, 2023 · 2 comments

Comments

@Laykou
Copy link

Laykou commented Sep 7, 2023

Is it possible to anonymize values in JSONs (simple) structure?

Let's say I have JSONB column:

data
----
{"first_name":"Michael","phone":"+123456"}

and I want to anonymize data->>'first_name'. Would that work too?

@jmmuve
Copy link

jmmuve commented Jan 14, 2024

I'm interested too

@JargeZ
Copy link

JargeZ commented Nov 6, 2024

Here is rough workaround

const { abn } = require('/usr/local/lib/node_modules/@phuocng/fake-numbers');
const faker = require('/usr/local/lib/node_modules/pg-anonymizer/node_modules/faker');

const omitJsonField = (field, val, newFieldValue = 'Omitted') => {
  const parsed = JSON.parse(val);
  if (!parsed) {
    return val;
  }

  // TODO: You can recursively search for the field as well

  const newVal = {
    ...parsed,
    [field]: newFieldValue
  }

  return JSON.stringify(newVal);
}

module.exports = {
  omitReference: (val) => {
    return omitJsonField("Reference", val);
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants