Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7947097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:20:05+00:00 2026-06-04T01:20:05+00:00

I’m a beginner with this so sorry for the silly question, I have a

  • 0

I’m a beginner with this so sorry for the silly question,

I have a json with a large amount of data in it and I have to process this file in php. (Edit/Delete/Filter Objects).

How I am thinking to do it: a class that contains a list of objects and the functions to load objects from json and another to write them back. Also, other functions for operations over the list.

What I’m asking is what is the best way to do this, because my idea is the simplest one, than each time I click on : Edit, Delete, Filter I have to reload again and again the loatJsonObjects(), can you give me a better way to do this, that won’t make so many operations each time? Thank you !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:20:06+00:00Added an answer on June 4, 2026 at 1:20 am

    So, I shouldn’t really attempt to write one for you, but I’m in a really good mood this morning. Try this:

    Class Json_Handler {
      private $json_object;
      public function __construct($json_data) {
    
        if(is_object($json_data) {
          $this->json_object = $json_data;
        }
    
      }
    
      public function edit($key, $value) {
    
        if(isset($this->json_data[$key])) {
         $this->json_data[$key] = $value;
         return $this;
        }
        else {
         return FALSE;
        }
    
      }
    
      public function delete($key) {
        if(isset($this->json_data[$key])) {
          unset($this->json_data[$key]);
          return $this;
        }
        else {
          return FALSE;
        }
      }
    
      public function filter($on = 'key', $filter == NULL) {
         $filtered_objects = array();
         switch($on) {
           case 'key':
           default:
            foreach($this->json_data as $key => $value) {
              if($key == $value) {
                $filtered_objects[] = array($key => $value);
              }
            }
            break;
            case 'value':
             foreach($this->json_data as $key => $value) {
               $filtered_objects[] = array($key => $value);
             }
            break;
         }
         return $filtered_objects;
      }
    
      public function get_json() {
        return json_encode($this->json_data);
      }
    
      public function set_json($json) {
        $this->json_data = (is_object($json) ? $json : json_encode($json));
        return $this;
      }
    
    }
    

    You can then use it as so:

    $my_json_data = json_decode([...]);
    $json = new Json_Handler($my_json_data);
    echo $json->edit('test', 'now i have this value')
              ->delete('test')
              ->filter('key', 'bar');
              ->set_json(json_encode($new_json)
              ->get_json();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.