-1

I have a JSON file that represents a job posting. In this JSON file, it describes things like the job title, salary range, posting client, and so on. I am wondering if it is possible to load this file (via File.ReadAllText), loop through all the lines, and then change the value of each line of the JSON to a constant based on the type. For example, if a string is encountered, change to "Lorem Ipsum".

Here is example JSON I am working with:

{
"value": [
{
  "id": "C17548AD-A7CA-44CC-9D25-1655B7FF101A",
  "job_id": "195747",
  "agency": "OFFICE OF LABOR RELATIONS",
  "posting_type": "Internal",
  "num_of_positions": 1,
  "business_title": "Computer Associate (Software)",
  "civil_service_title": "COMPUTER ASSOC (SOFTWARE)",
  "title_code_no": "13631",
  "level": "02",
  "salary_range_from": 63226,
  "salary_range_to": 88002,
  "salary_frequency": "Annual",
  "work_location": "40 Rector Street New York Ny",
  "division_work_unit": "Systems Development",
  "job_description": "Under general supervision with varying degrees of latitude of independent initiative and judgment, the position is responsible for the design, implementation, enhancement, and maintenance of computer applications, systems, database programming and/or related software functions; performing related systems work.  Will work with NYC Automated Personnel System (NYCAPS) Application that uses the PeopleSoft/Oracle SQL server.  Will work with Premium Accounting & Central Enrollment System (PACES) Application that uses mainframe ADABAS/NATURAL until the application is migrated completely to NYCAPS.  Will work with online and batch processing on mainframe until complete migration to NYCAPS.",
  "minimum_qual_requirements": "(1) A baccalaureate degree from an accredited college, including or supplemented by twenty-four (24) semester credits in computer science or a related computer field and one (1) year of satisfactory full-time computer software experience in computer systems development and analysis, applications programming, database administration, systems programming or data communications; or  (2) A four year high school diploma or its educational equivalent and five (5) years of full-time satisfactory computer software experience as described in “1†above; or  (3) A satisfactory combination of education and experience that is equivalent to ''1'' or ''2'' above. A college education may be substituted for up to two years of the required experience in ''2'' above on the basis that sixty (60) semester credits from an accredited college are equated to one year of experience. In addition, twenty-four (24) semester credits from an accredited college or graduate school in computer science or a related field, or a certificate of at least 625 hours in computer programming from an accredited technical school (post high school), may be substituted for one year of experience. However, all candidates who attempt to qualify under option “3†must have at least a four-year high school diploma or its educational equivalent and at least two years of satisfactory full-time computer software experience as described in “1†above.    To receive credit, all college credits in computer science or a related computer field and/or the certificate in computer programming must be listed in Section A.6 on page 2 of the Education and Experience Test Paper.    Some examples of unacceptable experience are: End users of a computer system, program or software package; experience in the areas of computer technical support, computer operations; data entry/data retrieval; pure quality assurance (QA) auditing and   analysis; hardware installation; help desk; teaching; telecommunications; experience in productivity software products (e.g. word processing, spreadsheet, presentation, and database software, etc.); superficial use of preprogrammed software without   complex programming, design and implementation.",
  "preferred_skills": "PeopleSoft/Oracle SQL ADABAS/NATURAL JCL,VM/TSO,MVS, CICS/VS Microsoft SQL Unix, VB.Net, C#, FoxPro is a plus Proficient in Microsoft Office",
  "additional_information": "",
  "to_apply": "To apply please submit your cover letter and resume electronically using one of the following methods:  City Employees: Apply through Employee Self Service (ESS) at www. nyc.gov/ess  All Other Applicants:  Go to www.nyc.gov/careers  SEARCH FOR JOB ID# 195747  Submission of a resume is not a guarantee that you will receive an interview.",
  "hours_per_shift": "",
  "recruitment_contact": "",
  "residency_requirement": "New York City Residency is not required for this position",
  "posting_date": "2015-05-29T07:00:00Z",
  "post_until": "2015-06-11T07:00:00Z",
  "posting_updated": "2015-05-29T07:00:00Z",
  "process_date": "2015-06-02T07:00:00Z",
  "geo_location": {
    "type": "Point",
    "coordinates": [ -74.1279859095812, 40.6359634548426 ]
  },
  "tags": []
 }
 ]}

If strings such as those in "business_title" and "job_description" are encountered, this should be changed to "Lorem Ipsum".

Saveen
  • 4,120
  • 14
  • 38
  • 41
user3010406
  • 541
  • 2
  • 8
  • 22
  • Open it as a file of strings, split by line, split by : if the second parameter on a line has " at the front its a string, otherwise its not... – BugFinder Jun 11 '19 at 14:15
  • 3
    Yes this is definitely possible. What's your question? – Martin Jun 11 '19 at 14:15
  • It looks like simple enough to use `string.Replace` such as `content.Replace(@"""business_title""", @"""Lorem Ipsum""")`. – sardok Jun 11 '19 at 14:26
  • 2
    Assuming you want to replace the **string values** (which is unclear) and are using [tag:json.net], see [With json.net, is there a shortish way to manipulate all string fields?](https://stackoverflow.com/q/46148971). See also [Loading a .json file into c# program](https://stackoverflow.com/a/18538469). – dbc Jun 11 '19 at 17:28

1 Answers1

-1

To check the type use this line in the loop:
if (innerItemChild.FirstOrDefault()?.Type == JTokenType.String)

For more information please see the image. I used your sample json. I hope it will help.