Question

In: Computer Science

I want to remove the unnecessary characteristics from json. bad JSON "{\n \"response\": {\n \"Id\": \"1234\",\n...

I want to remove the unnecessary characteristics from json.

bad JSON

 "{\n  \"response\": {\n    \"Id\": \"1234\",\n    \"la\": [\n      {\n        \"op\": \"pic\",\n        \"lbl\": \"33609\",\n 

I want the json to be like this

{"response":{"Id":"1234","la":[{"op":"pic","lbl":"33609","

I have tried to used URLDecoder.decode(param1AfterEncoding, "UTF-8"); but it didn't fix it. I would apperciate any help

Solutions

Expert Solution

you can use the following program and check if it works........

import json
import sys
from pkgutil import simplegeneric

@simplegeneric
def get_items(obj):
    while False: # no items, a scalar object
        yield None

@get_items.register(dict)
def _(obj):
    return obj.items() # json object.

@get_items.register(list)
def _(obj):
    return enumerate(obj) # json array

def strip_whitespace(json_data):
    for key, value in get_items(json_data):
        if hasattr(value, 'strip'): # json string
            json_data[key] = value.strip()
        else:
            strip_whitespace(value) # call recursively

data = json.load(sys.stdin) # read json data from stdin
strip_whitespace(data)
json.dump(data, sys.stdout, indent=2)

..............................................................................................................

and also you can try this one to remove bakslashes.....

import json
# result = json.dumps(result)

with open('result.json', 'w') as fp:
    json.dump(result, fp, indent=4)

Related Solutions

I want to know how to get the "temp" information from a API response like this...
I want to know how to get the "temp" information from a API response like this in javascript: { "coord": { "lon": -122.08, "lat": 37.39 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01d" } ], "base": "stations", "main": { "temp": 282.55, "feels_like": 281.86, "temp_min": 280.37, "temp_max": 284.26, "pressure": 1023, "humidity": 100 }, "visibility": 16093, "wind": { "speed": 1.5, "deg": 350 }, "clouds": { "all": 1 }, "dt": 1560350645, "sys": { "type": 1, "id": 5122, "message":...
combinatioal & sequential circuits in computer application i want to remove this question please refund this...
combinatioal & sequential circuits in computer application i want to remove this question please refund this i don't want answer.of this it was typed by mistake
Python programming problem! Suppose that there is a json file called data from the desktop. I...
Python programming problem! Suppose that there is a json file called data from the desktop. I want to print the value with the key of "year" and "country". Json file below: { "A":{ "year":11, "grade":A, "country":America}, "B":{ "year":18, "grade":C, "country":England}, "C":{ "year":19, "grade":B, "country":China},} I want a code that I can only replace the name of key from year to grade and the code could be work.
I have n books with n different titles. I want to put them on the shelves...
I have n books with n different titles. I want to put them on the shelves in my library. How many different ways are there to arrange them on one shelf? On two shelves? On k shelves?
We want to remove a carcinogenic substance (which of course is in a small concentration) from...
We want to remove a carcinogenic substance (which of course is in a small concentration) from some industrial waste. As an engineer, you have found a special material in the shape of a sphere of radius r0, in which the substance diffuses with diffussivity of D(eff). Within the sphere, the substance is consumed (is bound) at an independent rate of its concentration, i.e. its consumption per unit volume is ko.[ C(A,G)=-Ko] The concentration of this substance in radious R is...
i want to know a good human-machine interface and a bad human-machine interface
i want to know a good human-machine interface and a bad human-machine interface
For this bad news message, I want you to use the AIM planning process, the FAIR...
For this bad news message, I want you to use the AIM planning process, the FAIR test, and the components of Bad News Messages as described in Chapter 11, particularly pages 336 to 345 Case study: You are the manager for Macy’s Department Store and you manage 25 part-time employees. Many are retired individuals who are working to supplement their social security payments. It is difficult sometimes to hire and keep part-time employees because the pay is minimum wage and...
I want to know why I can not get N(should contain 1000 number) N<-vector() for (k...
I want to know why I can not get N(should contain 1000 number) N<-vector() for (k in 0:999){ y=vector() for(i in 0:999){ r1=runif(1) r2=runif(1) x1=-log(r1) x2=-log(r2) k=(x1-1)^2/2 if (x2 >= k){ r<-runif(1) if (r>0.5){ y[i]= x1 }else{ y[i]= -x1 } } y.1<- y[-which(is.na(y))] number<-length(y.1) } N[k]<-number } N
I want this code to be written in c++. Take a string of length n as...
I want this code to be written in c++. Take a string of length n as an input from the user such that n>=8 and only lower-case letters (a-z) are allowed as valid string characters. Deleting a letter from the string removes all the occurrences of that letter. The objective is to find the longest possible string such that it is left with only two unique letters and no two consecutive characters in a string are the same. If there...
Please I want the similarities between CD4 and CD8.. (In response to pathogenic infection) And you...
Please I want the similarities between CD4 and CD8.. (In response to pathogenic infection) And you can explain that by the steps of infection
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT