How to remove specific lines with a pattern inside a json file? - json

I have a very large json file with an error that I need to fix.
{
id: 1,
name: 'Human',
type: {
id: { <==== here
id: 2,
name: 'Body',
image: 'body.png',
}, <==== here
},
},
I need to remove this id: { and the closing brace } lines inside type. How to remove them to make the object look like this?
{
id: 1,
name: 'Human',
type: {
id: 1,
name: 'Body',
image: 'body.png',
},
},

Related

Translating form labels inside json with i18n (react)

I'm using i18n(v9) to translate a lot of text in a big react project. It's working as intended in cases like:
<Intro
title={details.title}
subtitle={t('resume-upload subtitle')}
description={t('resume-upload description 2')}
/>
However, In a form component that uses these 2 imports:
import { Form } from 'mobx-react-form';
import validatorjs from 'validatorjs';
When I try to translate labels within the code like this:
setup() {
const { t } = this.props;
return {
fields: [
{
name: 'step',
value: 0
},
{
name: 'firstName',
label: t('Firstname'),
rules: 'required|string|between:2,25'
},
{
name: 'lastName',
label: t('Achternaam'),
rules: 'required|string|between:2,25'
},
{
name: 'emailaddress',
label: t('Email'),
rules: 'required|email|string'
},
{
name: 'phonenumber',
label: t('Telephone number'),
rules: 'required|string|telephone'
},
{
name: 'cv',
label: t('resume')
},
{
name: 'terms',
label: 'Terms',
value: false
},
{
name: 'newFile',
label: '',
value: true
},
{
name: 'noFile',
label: '',
value: false
}
]
};
}
}
export default withNamespaces()(UploadForm);
The t function gives an error in a parent file:
TypeError: form.values is not a function
Is there a way to translate json files like the way I'm attempting?

Angular4 error message shows code which differs from the code that's supposed to be serving

I'm writing an app to go into a website, which is intended to calculate simplex algorithms. At the moment I am attempting to create functionality whereby the user can enter the number of coefficients and constraints, name these whatever they wish, and have the app spawn the relevant number and type of UI elements relative to the user's input. Here's what appears to be the relevant portion of the code (app.component.ts):
import { Component } from '#angular/core';
[...]
export class UIComponent {
id: 1;
name: string;
value: number;
type: string;
}
//* Mock data */
const UICOMPONENTS: UIComponent[] = [
{ id: 1, name: 'coefficient1', value: 4, type: '1dslide' },
{ id: 2, name: 'constraint1', value: 2, type: '2dslide' },
{ id: 3, name: 'min_max', value: 0, type: 'switch' },
{ id: 4, name: 'profit', value: 100, type: 'num_output' }
];
[...]
export class AppComponent {
title = 'SimutronX';
uicomponents = UICOMPONENTS;
[...]
}
This produces an error on screen saying:
Failed to compile.
/root/simutronx/simutron-app/src/app/app.component.ts (18,49): ',' expected.
Which relates to this line:
{ id: 2, name: 'constraint1', value: 2, type: '2dslide' },
Specifically the digit 2 in 2dslide. The error message (it's extremely long so I won't reproduce it all) also includes:
./src/app/app.component.ts
Module parse failed: /root/simutronx/simutron-app/node_modules/#ngtools/webpack/src/index.js!/root/simutronx/simutron-app/src/app/app.component.ts Unexpected token (22:85)
You may need an appropriate loader to handle this file type.
| var UICOMPONENTS = [
| { id: 1, name: 'coefficient1', value: 4, type: '1dslide' },
| { id: 2, name: 'constraint1, value: 2, type: ', 2: dslide, ' },: { id: 3, name: 'min_max', value: 0, type: 'switch' }, },
| { id: 4, name: 'profit', value: 100, type: 'num_output' }
| ];
Which is particularly confusing since, as you can see, that's not how I wrote the code. What's going on here?
You have an error in UIComponent type :
export class UIComponent {
id: number; //HERE
name: string;
value: number;
type: string;
}
Here a plunker :http://plnkr.co/edit/e6GrylSWznwbYD9VpK2C

How to access this specific JSON key

This is my JSON file from which I want to access "tr_name" which is inside var InspectorDefs but I can't find the way.Any help please?
JSON FILE:
var InspectorDefs = {
'link': {
inputs: {
attrs: {
'.attributes': {
'tr_name': { type: 'text', group: 'attributes', label: 'Name', index: 1 },
'tr_description': { type: 'text', group: 'attributes', label: 'Description', index: 2 },
'tr_rules': { type: 'select', options: [], group: 'attributes', label: 'Rule', index: 3 },
'tr_value': { type: 'select', options: ['true', 'false'], group: 'attributes', label: 'Value', index: 4 },
'tr_rule_source': { type: 'select', options: ['BPM', 'Drools', 'iLog'], group: 'attributes', label: 'Rule source', index: 5 }
},
},
},
},
};
I want to pass tr_name path here but I am desperate:
cell.on('change:tr_name', function(cell, change, opt) {})
if you are just looking for how to access your properties in javascript then you would reference it like this
InspectorDefs.link.inputs.attrs[".attributes"].tr_description
JSON objects can be referenced as properties or dictionaries, i am assuming you are having issues with the ".attributes"?
JsFiddle
you can use [] as in array or map.
var tr_name = InspectorDefs['link']['inputs']['attrs']['.attributes']['tr_name'];
But in your case I guess you want to call some function when the attribute of some html tag changed. so you can use the actual html tag generated by this json file which can be found from the web page generated or from my guess it is: <Name> tag as read from the json file

Meteor: JSON doesn't match SimpleSchema

I got this SimpleSchema for a collection in my meteor-app
Collection.attachSchema(new SimpleSchema({
title: { type: String },
slug: { type: String, unique: true },
language: { type: String, defaultValue: "en" },
'category.element': { type: String, optional: true }
}));
And I try to insert this JSON-data, but I get insert failed: Error: Category must be an object at getErrorObject
{
"_id" : "25uAB4TfeSfwAFRgv",
"title" : "Test 123",
"slug" : "test_123",
"language" : "en",
"category" : [
{
"element" : "Anything"
}
]
}
What is wrong with my JSON-data? Or what's wrong with my SimpleSchema. I can change both of them to match the best way.
You need to first declare the object, like,
Collection.attachSchema(new SimpleSchema({
...,
....,
category: {type: [Object], optional: true}
}));
After that you can extend/define object field(s) like,
Collection.attachSchema(new SimpleSchema({
....,
....,
category: {type: [Object]},
'category.$.element': {type: String}
}));
use '$' if its a Array Object ([Object]), If only object then then do not use '$'.
If you do not sure about Object Structure, use another parameter blackbox:true
like,
category: {type: [Object], blackbox: true}
The simplest solution is to define category as an array of objects in your schema:
Collection.attachSchema(new SimpleSchema({
title: { type: String },
slug: { type: String, unique: true },
language: { type: String, defaultValue: "en" },
category: { type: [Object], optional: true }
}));
This will get you unstuck.
If you want to be more specific about the contents of category then you can define a sub-schema for category. For example:
CategorySchema = new SimpleSchema({
element: { type: String }
});
Collection.attachSchema(new SimpleSchema({
title: { type: String },
slug: { type: String, unique: true },
language: { type: String, defaultValue: "en" },
category: { type: [CategorySchema], optional: true }
}));

how to display child and parent JSON data in each row of the list in Sencha using model and store

My server returning the following nested json. I want to display the fullname and text comes as a each row of the list. like,
apple Message2
apple Message1
Instead of this, I got one row contains all the data as the following:
apple Message2 Message1.
If json may be like this:
"packet": {
"fullname": "apple",
"wants": {
"text": "Message 2",
}
}
we can mention the field in model:
fields: [{
name: 'fullname',
type: 'string'
}, {
name: 'text',
mapping: 'wants.text'
}]
But I have array of wants, how to access the wants array through mapping?
json String:
"packet": {
"fullname": "apple",
"wants": [{
"text": "Message 2",
}, {
"text": "Message 1",
}]
}
Model:
Ext.define('myApp.model.Packet', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'fullname',
type: 'string'
}, {
name: 'text',
mapping: 'wants[0].text'
} //Is this right? If right mean how to get next wants.how to iterate?
]
}
});
Store:
Ext.define('myApp.store.WantsStore', {
extend: 'Ext.data.Store',
config: {
model: 'myApp.model.Packet',
proxy: {
type: 'ajax',
url: 'server path',
reader: {
type: 'json',
rootProperty: 'packet'
}
}
}
});
List:
Ext.define('myappApp.view.WantsList', {
extend: 'Ext.List',
xtype: 'wantslist',
config: {
itemCls: 'my-dataview-item',
loadingText: 'Loading items...',
emptyText: '<div class="notes-list-empty-text">No Wants found.</div>',
itemTpl: '<div><p class="list-item-title">{fullname} <span id="time" class="list-item-title">{text}</span></p>'
}
});
Thanks in Advance!